Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery button to check all check boxes issue

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/

like image 827
AJFMEDIA Avatar asked May 11 '11 16:05

AJFMEDIA


People also ask

How do you check all checkboxes are checked or not in jQuery?

To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);

How do I check uncheck all checkboxes with a button using jQuery?

Abstract: To Select or Deselect Checkboxes using jQuery, all you need to do is use the prop() method along with the change event to achieve the requirement in a couple of lines of code. Gmail has a nice option where you can select and deselect multiple checkboxes (Emails) using the 'Select All' checkbox.

How can I check all checkboxes within a div using jQuery?

click(function(){ $(':checkbox'). prop("checked", true); alert("1"); }); $('#deselectChb'). click(function(){ $(':checkbox'). prop("checked", false); alert("2"); });

How do I check all check boxes?

In order to select all the checkboxes of a page, we need to create a selectAll () function through which we can select all the checkboxes together. In this section, not only we will learn to select all checkboxes, but we will also create another function that will deselect all the checked checkboxes.


1 Answers

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

like image 161
Naftali Avatar answered Sep 20 '22 17:09

Naftali