Urs
Urs

Reputation: 5122

Open a child node in jsTree

I would like jsTree (3.0.2, with a static ul list, no JSON, no AJAX) to open a child node on load. Actually, the parent node of the current child node.

The raw HTML would look like this:

<ul>
  <li id="1">
      <ul>
        <li id="2">
           <ul>
              <li id="3" class="current">
              </li>
           </ul>
        </li>
      </ul>
      <ul>
        <li id="4">
           <ul>
              <li id="5">
              </li>
           </ul>
        </li>
      </ul>
  </li>

And the desired output is simply

1
+-2
 +-3
+-4

I have checked about every other post here regarding open_nodeand similar. I haven't managed to get anything to work.

Regarding the post How do I programmatically select a node in jsTree and open all parents: It seems to be the same question, but I am not sure if it applies to older versions.

Upvotes: 1

Views: 1607

Answers (1)

Jeevi
Jeevi

Reputation: 1052

To make a node initially selected you can set the "jstree-clicked" class on the "a" element.

Similarly you can set the jstree-open class on any "li" element to make it initially expanded, so that its children are visible.

JSBIN Link

Upvotes: 4

Related Questions