If one checkbox is selected, automatically select the rest on page jQuery?
If the checkbox with the class "selectAll" is checked I want the rest of the checkboxes on the page to aut开发者_JAVA技巧omatically be checked. I got this working with the following:
$('.selectAll').click(function() {
$("input[type='checkbox']").attr('checked', true);
});
But I want all checkboxes to be unchecked when select all is clicked again, I can't get that part working. How can that be done?
You could change true
to other parameters...
$('.selectAll').click(function() {
$("input[type='checkbox']").attr('checked', this.checked);
});
(Test: http://jsbin.com/ogobi5)
精彩评论