Publishing System Settings Logout Login Register
Check/Uncheck all checkboxes with jQuery
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on October 5th, 2009
5669 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 Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top