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

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -