I got this code from stackoverflow which looks like a pretty good \"select all\" checkbox solution, any ideas why it fails after 2nd click?
http://jsfiddle.net/R9zj
You code does not work on jQuery 1.9 and is because of framework of jQuery version you have, choose 1.8.3 and it would work.
Live Demo
$(document).ready(function () {
$(document).on("click", ".selectall2", function () {
$(this).closest('tr').find('input[type=checkbox]').attr('checked', this.checked);
});
});
You should use prop instead of attr for jQuery 1.6 and above
Live Demo
$(document).ready(function () {
$(document).on("click", ".selectall2", function () {
$(this).closest('tr').find('input[type=checkbox]').prop('checked', this.checked);
});
});
As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method, jQuery doc