Check All checkboxes using JQuery
I am using some
jQuery in a project and I needed to make a list of checkboxes to be checked and unchecked on a certain event,
similar to what all email clients are doing when you click check all emails, the natural javascript code for this will be a hell with all the loops and checking for element types in the DOM element tree which will seem like a code for controlling a missile in the outer space have a look on the jQuery version of this code
$(document).ready(function(){
$("#aCheckAll").click(function(){
$("#myTable").find("input[@type$='checkbox']").each(function(){
this.checked = true;
});
});
});
I had a a table named "myTable" and it has columns with checkboxes in it, and I had a anchor named "aCheckAll" so all what I had to do is hooking the click event to the anchor and inside the event I am searching for all the checkboxes in the table and for each result item I am setting the checked property to true.
Very cool and attractive :)