Publishing System Settings Logout Login Register
Check/Uncheck all checkboxes with jQuery
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on October 4th, 2009
441 views
JavaScript

HTML:

 

 

<input type=\"checkbox\" id=\"all\" /> Check/Uncheck all
<div id=\"check\">
 <input type=\"checkbox\" /> 1<br />
 <input type=\"checkbox\" /> 2<br />
 <input type=\"checkbox\" /> 3<br />
 <input type=\"checkbox\" /> 4<br />
 <input type=\"checkbox\" /> 5<br />
 <input type=\"checkbox\" /> 6<br />
 <input type=\"checkbox\" /> 7
</div>

 

 

The function that does the magic is find(); this function finds all elements in our case input that has the type = checkbox. Then it sets the checked atribute to true.

I used the toggle function for first (checks all) and second click (unchecks all)

 

 

<script type=\"text/javascript\" src=\"assets/jquery.js\"></script>
<script>
$(document).ready(function() {
 $('#all').toggle(
 function() {
 $('#check').find('input[type=checkbox]').attr('checked', true);
 },
 function() {
 $('#check').find('input[type=checkbox]').attr('checked', false);
 });    
});
</script>

 

Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
cigraphics

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Get Started Credit Corner Get Started Credit Corner