She_rish She_rish - 1 year ago 265
Javascript Question

Find node clicked on jsTree click event to expand or collapse

I have 4 levels of tree:

- Reg1
-level 2
-level 3
-level 4
+level 2
level 2
level 3
level 4
level 2
level 2
level 3
level 4
level 2
level 2
level 3
level 4
level 2

I have implemented this using using
struts2 jQuery JSTree
plugin using JSON data.

If I select any child node (e.g.: Reg1 --> Level 2 --> level 3 --> level 4), when I try to collapse or expand the tree node which contains the selected child (level 4), it triggers the click event.

When I expand/collapse on the other nodes which are in a different hierarchy (Reg 2 or Reg 3 or Reg 4), then it won't trigger the click event.

Is there anyway we can capture which element is clicked on the click event, so that if it's an image with INS tag then I can skip my logic?


Check out the More widgets -> Tree part

use the onClickTopics to catch the click event



And you can get which element is clicked in the listen topic

$.subscribe('treeClicked', function(event, data) {
          var item =;
          alert('Clicked ID : ' + item.attr("id") + ' - Text ' + item.text());