Javascript/jQuery check all check boxes function.
June 16, 2008 – 12:14 pmYou would think a check all function would be pretty easy in jQuery, and it is if all of the checkboxes have the same name. If they don't things get tricky.
In this example, I have an anchor named chk_all that the user can click to check all. All of my checkboxes to be checked are in a table named search_results.
var toggle = 1; $("#chk_all").click(function(){ $("#search_results").find("input[@type$='checkbox']").each(function(){ if(toggle) { this.checked = true; } else { this.checked = false; } }); if(toggle) { toggle = 0; } else { toggle = 1; } return false; });
Sorry, comments for this entry are closed at this time.