JQuery button to check all checkboxes

I have a button that checks all the checkboxes in divand does not check.

However, if I have to manually select one checkbox, then click the "Check All" button, and then uncheck all, the checkbox that was manually checked will not be canceled!

Any ideas?

http://jsfiddle.net/hM5bu/1/

+5
source share
2 answers

Thats because jQuery has been changed to 1.6

Using attrinstead propis what violates it.

Try using propinstead

Updated script: http://jsfiddle.net/hM5bu/2/

: .prop() vs .attr() prop attr jQuery 1.6

+6

:

<input type="checkbox" name="todos" id="todos" /> All<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="1" />1<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="2" />2<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="3" />3<br/>
<input class="marcartodos" type="checkbox" name="marcado[]" value="4" />4<br/>

<script type="text/javascript">

$(function() {

$("#todos").click(function() {                          
if ($(this).is(':checked'))                         
$(".marcartodos").attr('checked', true);
else 
$(".marcartodos").attr('checked', false);
});

});

</script>
-1

All Articles