She_rish She_rish - 2 years ago 352
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?

Answer Source

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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download