Jquery randomly checks a checkbox

What is wrong with this checkbox controller?
JQuery will change the attribute in html, but not the graphic checkbox ...

HTML

<input type="checkbox" checked="checked"/> <input type="checkbox"/> <a href="#" class="no">off</a> <a href="#" class="yes">on</a> 

Js

 $(document).ready(function(){ $('.yes').click(function(){ $('input:checkbox').attr('checked','checked'); }); $('.no').click(function(){ $('input:checkbox').removeAttr('checked'); }); }) 

test

http://jsfiddle.net/ehijon/Jmn3r/

+4
source share
1 answer

Change the use of prop:

 $("input[type='checkbox']").prop('checked',true); // --Change to false to uncheck 

See script update: http://jsfiddle.net/Jmn3r/1/

+4
source

All Articles