dopeinc
dopeinc

Reputation: 69

JSTree list and anchor

Hey guys I need some help I have a JSTREE with some that redirect to a part of my html webpage Im tryin to figure out the jstree function that could help right now I have this : http://pastebin.com/ZTSYXWpt

this is the html code it is in french : http://pastebin.com/TpLhWASp Right now what is happening is that if I click on a node called either section 1 or 2 or 3 or wtv number that is there it redirect me on the node itself instead of the href link instead of the one that is in the li ANY HELP ?

( Im able to do it without the jstree click on a link with anchor and redirect the user on the page to that section but im unable to do it with the jstree )

this is the function that when you click on it it should redirect you to the specified section in the html page

$(document).ready(function() {
$('div').eq(0).jstree();
$("#catTree li").on("click", "a", function() {

    document.location.href = this;
});

});

this is part of html code that is creating my list in html

    <body>
    <h1>Categorie</h1>
    <div id="catTree">
        <ul class="n1">
            <span>Liste Categorie</span>
            <li>
                Categorie
                <ul class="n2">
                    <li>
                        <a class="menu" href="#section1">Section 1</a>
                    </li>
                    <li>
                        <a  class="menu" href="#section2">Section 2</a>
                    </li>

and this is where it should refer you when you click on the JStree node

            <header>

            <p>
                Nom fabricant
            <p>
                <a name="section1"> Section 1</a>
        </header>
        <br>
        <figure>
            <p>
                description1
            </p>
            <figcaption>
                blabla
            </figcaption>
            <img src="images/hat1.jpg" alt="hat"/>
        </figure>
        <br>
        <footer>
            <p>
                Prix : 00$$
            </p>
            <a href= "#section12"> Dernière section</a>
        </footer>

Clearer code if you want more info on it go into the html pastebin file but if you look at it there is 12 section that are exactly the same and I want those jstree node to redirect to those section

Upvotes: 1

Views: 2854

Answers (1)

Artem
Artem

Reputation: 833

It seems as dup of How to get I get leaf nodes in jstree to open their hyperlink

Check http://codepen.io/anon/pen/gPryPR

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

Upvotes: 2

Related Questions