Jquery checkbox does'n work (checked and unchecked) -
it's doesn't work ( why? can explain, please
function checkbox()     {         if($('.checkbox').prop('checked', true))         {             $('body').css('background','yellow');         }         else if ($('.checkbox').prop('checked', false))             $('body').css('background','blue');     }      
fiddle: https://jsfiddle.net/7rpel2gu/4/
thats answer html:
<input class="checkbox" type="checkbox" />   js:
$(document).ready(function(){   $('.checkbox').on('click', function(){     checkbox( $(this) );   }); });  function checkbox($this){   if( $this.prop('checked') ){       $('body').css('background-color','yellow');}   else{       $('body').css('background-color','blue'); } }   p.s. code not work, because $(input).prop('checked', true) - set input checked, $(input).prop('checked') give input.state of checked.
p.p.s read https://api.jquery.com/prop/
Comments
Post a Comment