How to get I get leaf nodes in jstree to open their hyperlink when clicked when using jstree ui

筅森魡賤 提交于 2019-11-30 09:16:48

for new versions;

$("#demo2").jstree().bind("select_node.jstree", function (e, data) {
     var href = data.node.a_attr.href;
     document.location.href = href;
});

I know this post is kinda old, but here what I did to make this work :

html:

<div id="entryPointTree">
    <ul>
        <li>Produits des mains
           <ul>
              <li><a href="http://www.google.ca" class="jstree-clicked">Lien 1</a></li>
              <li>item 2</li>
           </ul>
        </li>
        <li>Produits des pieds</li>
    </ul>
</div>

js:

$(document).ready(function() {
    $("#entryPointTree").jstree({ "plugins" : ["themes","html_data","ui"] });
    $("#entryPointTree li").on("click", "a", 
        function() {
            document.location.href = this;
        }
    );
});

Try This.

$("#demo2").jstree().bind("select_node.jstree", function (e, data) { 
        var href = data.rslt.obj.children("a").attr("href"); 
        document.location.href = href; 

      //  $("#the_div").load(href); 
    }) ;

My solution for v3.3.4, it works fine!

tree.jstree().on("click", ".jstree-anchor", function() {
    document.location.href = this.href;
});

None of the other answers do what I want: multiple <a> tags in the title of the node. This is what worked for me:

HTML

<div id="object-tree">
  <ul>
     <li>SomeTitle <a href="/link1" target="_blank">link1><a href="/link2" target="_blank">link2</a></li>
  </ul>
</div>

Javascript

jQuery('#object-tree').jstree().bind("select_node.jstree", function (e, data) {
  // Allow links to work from within jstree nodes
  window.open( jQuery(data.event.originalEvent.originalTarget).attr('href'), '_blank');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!