Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8671853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:03:23+00:00 2026-06-12T19:03:23+00:00

I have a strange problem with JSTree and Ajax. I generate my tree via

  • 0

I have a strange problem with JSTree and Ajax.

I generate my tree via an Ajax/PHP request which generates HTML (with UL,LI,A tags) using…

$.ajax({
    url: 'ajaxTreeView.php?method=edit&partid='+partId,
    cache: false,
    success: function(tree)
    {
        $('#treeViewer').html(tree);
    }});

and activate JStree on the code using…

options = 
{
    "core": { animation: 120 },
    "themes": { theme: 'corral', dots: true },
    "types": 
    { 
        "types": 
        { 
            "parent": { "icon": { "image": "images/custom/Legend/node_select.png" } },
            "child": { "icon": { "image": "images/custom/Legend/node_select_child.png" } },
            "current": { "icon": { "image": "images/custom/Legend/node.png" } }
        }
    },
    "plugins": [ "html_data", "types", "themes", "ui", "contextmenu", "cookies" ],
    "ui": { "select_limit" : 1 },
    "cookies": { "save_selected" : false }
};

$("#tree").jstree(options);

I can’t seem to get a node to select easily. I tried initially_select but this doesn’t seem to work and also isn’t ideal as I often want to programatically select node anyway.

I tried using…

$('#tree').jstree("select_node", '#ref565', true);

This works if I call the function via a hyperlink but doesn’t work if I call it after I initalise JStree.

I see from adding an alert (all this happens in the Ajax Success routine)…

$('#treeViewer').html(tree);
$("#tree").jstree(options);
alert('test');
$('#tree').jstree("select_node", '#ref565', true);

… that the tree has not rendered before the alert kicks off.

I added a setTimeOut…

$('#treeViewer').html(tree);
$("#tree").jstree(options);
setTimeout(function() {selectNode(565);},1250);
$('#tree').jstree("select_node", '#ref565', true);

… this works.

I’m clearly being stupid. Am I using the wrong syntax? Why would I have to set a delay in order to select a node?

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:03:24+00:00Added an answer on June 12, 2026 at 7:03 pm

    If you want to initially select certain nodes after the tree loads, you are supposed to use the initially_select option of the ui plugin. You said you tried it, but I don’t see it being used in the sample code you posted. Are you sure you are supplying correct IDs?

    To programmatically select nodes, you need to wait for the nodes you want to select to appear in the DOM first. Rather than using a timeout call back, I’m guessing it is more correct to bind to the loaded.jstree event, which ought to be called after the tree has finished loading and all tree elements are in the DOM, and do your programmatic select in there.

    Example code showing usage:

    $(function () {
    
        $("#tree")
            .jstree({ 
                // List of active plugins
                "plugins" : [ 
                    "ui"
                ],
    
                // UI & core - the nodes to initially select and open will be overwritten by the cookie plugin
                // the UI plugin - it handles selecting/deselecting/hovering nodes
                "ui" : {
                    // this makes the node with ID node_4 selected onload
                    "initially_select" : [ "#ref565" ]
                },
                // the core plugin - not many options here
                "core" : { 
                    // just open those two nodes up
                    // as this is an AJAX enabled tree, both will be downloaded from the server
                    "initially_open" : [ "#ref565" ] 
                }
            })
            .bind("loaded.jstree", function (e, data) {
                      $('#tree').jstree("select_node", '#ref565', true); 
            }) 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this strange problem parsing XML document in PHP loaded via cURL. I
I have strange problem with the delay function here using the HTML function with
I have strange problem with receiving data from socket. On client im using air
I have a strange problem with in-app billing RESTORE_TRANSACTION command. Every request RESTORE_TRANSACTION request
I have a strange problem. I do this query in a node.js server using
I have strange problem for which I can't think of a solution. I have
I have strange problem. I have class which behaves similar dropdown list. package test.view;
I have a strange problem, I'm using the code below to test for a
I have a strange problem. I've downloaded the latest php sdk. In there are
I have a strange problem when using Entity Framework code first. When I return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.