Check/Uncheck all checkboxes


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <div class="options">
  2. <ul>
  3. <li><a href="#" class="select-all">Select All</a></li>
  4. <li><a href="#" class="reset-all">Reset All</a></li>
  5. </ul>
  6.  
  7. <input type="checkbox" id="option1" /><label for="option1">Option 1</label>
  8. <input type="checkbox" id="option2" /><label for="option2">Option 2</label>
  9. <input type="checkbox" id="option3" /><label for="option3">Option 3</label>
  10. <input type="checkbox" id="option4" /><label for="option4">Option 4</label>
  11. </div>
  12. $('.select-all').live('click', function(){
  13. $(this).closest('.options').find('input[type=checkbox]').attr('checked', true);
  14. return false;
  15. });
  16.  
  17. $('.reset-all').live('click', function(){
  18. $(this).closest('.options').find('input[type=checkbox]').attr('checked', false);
  19. return false;
  20. });

URL: http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.