5

I have a button that checks all checkboxes in a div and un-checks.

However if I were to manually check one checkbox, then hit the Check all button and then uncheck all, the checkbox which was manually checked does not become unchecked!

Any ideas?

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

kapa
  • 77,694
  • 21
  • 158
  • 175
AJFMEDIA
  • 2,093
  • 6
  • 29
  • 52

2 Answers2

6

Thats because jQuery was changed in 1.6

Using attr instead of prop is what is breaking it.

Try using prop instead

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

See this question: .prop() vs .attr() for more about prop and attr in jQuery 1.6

Community
  • 1
  • 1
Naftali
  • 144,921
  • 39
  • 244
  • 303
-1

here is a solution:

<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>
Regis
  • 142
  • 5