sudheen

sudheen

  • 1.4k
  • 313
  • 83.7k

checkbox with treeview

Sep 10 2015 11:53 PM
  1. (function($)
  2. {
  3. function Tree() {
  4. var $this = this;
  5. function treeNodeClick()
  6. {
  7. $(document).on('click', '.tree li a input[type="checkbox"]', function() {
  8. $(this).closest('li').find('ul input[type="checkbox"]').prop('checked', $(this).is(':checked'));
  9. }).on('click', '.node-item', function() {
  10. var parentNode = $(this).parents('.tree ul');
  11. if ($(this).is(':checked')) {
  12. parentNode.find('li a .parent').prop('checked', true);
  13. } else {
  14. var elements = parentNode.find('ul input[type="checkbox"]:checked');
  15. if (elements.length == 0) {
  16. parentNode.find('li a .parent').prop('checked', false);
  17. }
  18. }
  19. });
  20. };
  21. $this.init = function() {
  22. treeNodeClick();
  23. }
  24. }
  25. $(function() {
  26. var self = new Tree();
  27. self.init();
  28. })
  29. }(jQuery))
above jquery used for selecting parent node all child node wil be selected.but my requirement is checking child node parent should be selected ..please give me solutions 

Answers (2)