check / uncheck checkboxes in tree


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

logical action on tree with checkboxes


Copy this code and paste it in your HTML
  1. $("ul input:checkbox").change(function(){
  2.  
  3. if ($(this).is(':checked')) {
  4. // children
  5. $(this).parent().find("input:checkbox").attr('checked', 'checked');
  6. }
  7. else {
  8. // children
  9. $(this).parent().find("input:checkbox").removeAttr('checked');
  10. // parents
  11. $(this).parents('li').each(function(){
  12. $(this).children('input:checkbox').removeAttr('checked');
  13. });
  14. }
  15. });

URL: http://jsfiddle.net/4QmNn/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.