How do I get jstree to automatically open path to the first tree node (and trigger function)How to get first character of string?jstree get highlight nodejsTree trigger select_node functionjsTree open node on rolloverjstree remember opened/closed tree nodesjstree how to open a nodeJavascript JStree open nodesHow to open checked nodes jstreeCan't open node in jstreejsTree: How to *set* opened/selected node by path (not ID)?

Cemented carbide swords - worth it?

Fun time! Guess what I am!

Microservices and Stored Procedures

Removing rows containing NA in every column

Why can't we use uninitialized local variable to access static content of its type?

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Why are there two bearded faces wearing red hats on my stealth bomber icon?

Is Zack Morris's 'time stop' ability in "Saved By the Bell" a supernatural ability?

Twelve Minesweeper mines that make twelve 4s

Is it safe to put a microwave in a walk-in closet?

Decimal “XOR” operator

Changing States from child through parent while obeying SOLID principles

Simulate a 1D Game-of-Life-ish Model

Why do we need to use transistors when building an OR gate?

How does one calculate the distribution of the Matt Colville way of rolling stats?

Can Brexit be undone in an emergency?

Get the encrypted payload from an unencrypted wrapper PDF document

Should the pagination be reset when changing the order?

Why do things cool down?

As an employer, can I compel my employees to vote?

Nested array references

Escape the labyrinth!

What can I actually do with a high credit score?

Dear Fellow PSE Users,



How do I get jstree to automatically open path to the first tree node (and trigger function)


How to get first character of string?jstree get highlight nodejsTree trigger select_node functionjsTree open node on rolloverjstree remember opened/closed tree nodesjstree how to open a nodeJavascript JStree open nodesHow to open checked nodes jstreeCan't open node in jstreejsTree: How to *set* opened/selected node by path (not ID)?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am using jstree



I build a tree, the leaf nodes contain a href which is then open in an iFrame on the same page. This is done by the function that is bound to whenever a node is selected in the jstree that checks to see if the node has a real href and then amends the iFrame accordingly, otherwise it opens the node.



<div class="container-fluid">
<div class="row">
<div class="col">
<div id='songchanges'>
<ul>
<li id='phtml_1'>
<a href='#'>E:MelcoTestMusicTestMusicTestMusicWAVMusicDead InsideNo.4</a>
<ul>
<li id="phtml_2">
<a href="FixSongsReport00440_body_aBE9p7eQo0baClCFB6BhPQ==.html"
target="_blank">
Flower
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-8">
<iframe id="processingResults" name="processingResults"
style="border:none; width:100%;height:500px">
</iframe>
</div>
</div>
</div>




<script>
$(function ()

$('#songchanges')
.jstree
(

'plugins' : ['themes','html_data','ui','cookie'],
'core' : 'initially_open' : [ 'phtml_1' ]

)
.bind('select_node.jstree',
function (e, data)

var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if(href!='#')

iframe.src = href;

else

$(this).jstree('toggle_node', data.node);


);

);
</script>


This works well, but when the the page is first displayed I don't want the iframe to be empty so I would like the jstree to automatically open the first leaf node and trigger the function to load the iFrame.



How do I do this ?










share|improve this question


























  • Maybe with "open_node (obj [, callback, animation])"?

    – nchokoev
    Mar 26 at 10:16











  • dont understand (my javascript skills are weak)

    – Paul Taylor
    Mar 26 at 19:00

















0















I am using jstree



I build a tree, the leaf nodes contain a href which is then open in an iFrame on the same page. This is done by the function that is bound to whenever a node is selected in the jstree that checks to see if the node has a real href and then amends the iFrame accordingly, otherwise it opens the node.



<div class="container-fluid">
<div class="row">
<div class="col">
<div id='songchanges'>
<ul>
<li id='phtml_1'>
<a href='#'>E:MelcoTestMusicTestMusicTestMusicWAVMusicDead InsideNo.4</a>
<ul>
<li id="phtml_2">
<a href="FixSongsReport00440_body_aBE9p7eQo0baClCFB6BhPQ==.html"
target="_blank">
Flower
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-8">
<iframe id="processingResults" name="processingResults"
style="border:none; width:100%;height:500px">
</iframe>
</div>
</div>
</div>




<script>
$(function ()

$('#songchanges')
.jstree
(

'plugins' : ['themes','html_data','ui','cookie'],
'core' : 'initially_open' : [ 'phtml_1' ]

)
.bind('select_node.jstree',
function (e, data)

var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if(href!='#')

iframe.src = href;

else

$(this).jstree('toggle_node', data.node);


);

);
</script>


This works well, but when the the page is first displayed I don't want the iframe to be empty so I would like the jstree to automatically open the first leaf node and trigger the function to load the iFrame.



How do I do this ?










share|improve this question


























  • Maybe with "open_node (obj [, callback, animation])"?

    – nchokoev
    Mar 26 at 10:16











  • dont understand (my javascript skills are weak)

    – Paul Taylor
    Mar 26 at 19:00













0












0








0


0






I am using jstree



I build a tree, the leaf nodes contain a href which is then open in an iFrame on the same page. This is done by the function that is bound to whenever a node is selected in the jstree that checks to see if the node has a real href and then amends the iFrame accordingly, otherwise it opens the node.



<div class="container-fluid">
<div class="row">
<div class="col">
<div id='songchanges'>
<ul>
<li id='phtml_1'>
<a href='#'>E:MelcoTestMusicTestMusicTestMusicWAVMusicDead InsideNo.4</a>
<ul>
<li id="phtml_2">
<a href="FixSongsReport00440_body_aBE9p7eQo0baClCFB6BhPQ==.html"
target="_blank">
Flower
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-8">
<iframe id="processingResults" name="processingResults"
style="border:none; width:100%;height:500px">
</iframe>
</div>
</div>
</div>




<script>
$(function ()

$('#songchanges')
.jstree
(

'plugins' : ['themes','html_data','ui','cookie'],
'core' : 'initially_open' : [ 'phtml_1' ]

)
.bind('select_node.jstree',
function (e, data)

var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if(href!='#')

iframe.src = href;

else

$(this).jstree('toggle_node', data.node);


);

);
</script>


This works well, but when the the page is first displayed I don't want the iframe to be empty so I would like the jstree to automatically open the first leaf node and trigger the function to load the iFrame.



How do I do this ?










share|improve this question
















I am using jstree



I build a tree, the leaf nodes contain a href which is then open in an iFrame on the same page. This is done by the function that is bound to whenever a node is selected in the jstree that checks to see if the node has a real href and then amends the iFrame accordingly, otherwise it opens the node.



<div class="container-fluid">
<div class="row">
<div class="col">
<div id='songchanges'>
<ul>
<li id='phtml_1'>
<a href='#'>E:MelcoTestMusicTestMusicTestMusicWAVMusicDead InsideNo.4</a>
<ul>
<li id="phtml_2">
<a href="FixSongsReport00440_body_aBE9p7eQo0baClCFB6BhPQ==.html"
target="_blank">
Flower
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="col-8">
<iframe id="processingResults" name="processingResults"
style="border:none; width:100%;height:500px">
</iframe>
</div>
</div>
</div>




<script>
$(function ()

$('#songchanges')
.jstree
(

'plugins' : ['themes','html_data','ui','cookie'],
'core' : 'initially_open' : [ 'phtml_1' ]

)
.bind('select_node.jstree',
function (e, data)

var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if(href!='#')

iframe.src = href;

else

$(this).jstree('toggle_node', data.node);


);

);
</script>


This works well, but when the the page is first displayed I don't want the iframe to be empty so I would like the jstree to automatically open the first leaf node and trigger the function to load the iFrame.



How do I do this ?







javascript jstree






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 9:58







Paul Taylor

















asked Mar 25 at 20:43









Paul TaylorPaul Taylor

2,09826 gold badges109 silver badges237 bronze badges




2,09826 gold badges109 silver badges237 bronze badges















  • Maybe with "open_node (obj [, callback, animation])"?

    – nchokoev
    Mar 26 at 10:16











  • dont understand (my javascript skills are weak)

    – Paul Taylor
    Mar 26 at 19:00

















  • Maybe with "open_node (obj [, callback, animation])"?

    – nchokoev
    Mar 26 at 10:16











  • dont understand (my javascript skills are weak)

    – Paul Taylor
    Mar 26 at 19:00
















Maybe with "open_node (obj [, callback, animation])"?

– nchokoev
Mar 26 at 10:16





Maybe with "open_node (obj [, callback, animation])"?

– nchokoev
Mar 26 at 10:16













dont understand (my javascript skills are weak)

– Paul Taylor
Mar 26 at 19:00





dont understand (my javascript skills are weak)

– Paul Taylor
Mar 26 at 19:00












1 Answer
1






active

oldest

votes


















0







+50









You can use the ready.jstree event handler to select a node after the tree is ready. The select_node function on the tree instance will trigger the select_node event.



$('#songchanges').jstree(

'plugins': ['themes', 'html_data', 'ui', 'cookie'],
'core': 'initially_open': ['phtml_1']

).on('select_node.jstree',
function (e, data)
var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if (href != '#') iframe.src = href;
else $(this).jstree('toggle_node', data.node);

).on('ready.jstree', function (e, data)
var leaf = null;
var getFirstLeaf = function (id)
var node = data.instance.get_node(id);
if(node.children.length > 0)
return getFirstLeaf(node.children[0]);

return data.instance.select_node(id); //Triggers select_node event
;
getFirstLeaf('phtml_1'); // Start from the root node id
);





share|improve this answer



























  • HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

    – Paul Taylor
    Mar 28 at 15:27












  • I've updated the code to traverse and select a leaf node.

    – Stephen S
    Mar 28 at 16:23











  • Great that works, if I change last line to getFirstLeaf('phtml_1');

    – Paul Taylor
    Mar 28 at 20:32











  • Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

    – Stephen S
    Mar 29 at 3:46










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346118%2fhow-do-i-get-jstree-to-automatically-open-path-to-the-first-tree-node-and-trigg%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0







+50









You can use the ready.jstree event handler to select a node after the tree is ready. The select_node function on the tree instance will trigger the select_node event.



$('#songchanges').jstree(

'plugins': ['themes', 'html_data', 'ui', 'cookie'],
'core': 'initially_open': ['phtml_1']

).on('select_node.jstree',
function (e, data)
var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if (href != '#') iframe.src = href;
else $(this).jstree('toggle_node', data.node);

).on('ready.jstree', function (e, data)
var leaf = null;
var getFirstLeaf = function (id)
var node = data.instance.get_node(id);
if(node.children.length > 0)
return getFirstLeaf(node.children[0]);

return data.instance.select_node(id); //Triggers select_node event
;
getFirstLeaf('phtml_1'); // Start from the root node id
);





share|improve this answer



























  • HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

    – Paul Taylor
    Mar 28 at 15:27












  • I've updated the code to traverse and select a leaf node.

    – Stephen S
    Mar 28 at 16:23











  • Great that works, if I change last line to getFirstLeaf('phtml_1');

    – Paul Taylor
    Mar 28 at 20:32











  • Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

    – Stephen S
    Mar 29 at 3:46















0







+50









You can use the ready.jstree event handler to select a node after the tree is ready. The select_node function on the tree instance will trigger the select_node event.



$('#songchanges').jstree(

'plugins': ['themes', 'html_data', 'ui', 'cookie'],
'core': 'initially_open': ['phtml_1']

).on('select_node.jstree',
function (e, data)
var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if (href != '#') iframe.src = href;
else $(this).jstree('toggle_node', data.node);

).on('ready.jstree', function (e, data)
var leaf = null;
var getFirstLeaf = function (id)
var node = data.instance.get_node(id);
if(node.children.length > 0)
return getFirstLeaf(node.children[0]);

return data.instance.select_node(id); //Triggers select_node event
;
getFirstLeaf('phtml_1'); // Start from the root node id
);





share|improve this answer



























  • HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

    – Paul Taylor
    Mar 28 at 15:27












  • I've updated the code to traverse and select a leaf node.

    – Stephen S
    Mar 28 at 16:23











  • Great that works, if I change last line to getFirstLeaf('phtml_1');

    – Paul Taylor
    Mar 28 at 20:32











  • Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

    – Stephen S
    Mar 29 at 3:46













0







+50







0







+50



0






+50





You can use the ready.jstree event handler to select a node after the tree is ready. The select_node function on the tree instance will trigger the select_node event.



$('#songchanges').jstree(

'plugins': ['themes', 'html_data', 'ui', 'cookie'],
'core': 'initially_open': ['phtml_1']

).on('select_node.jstree',
function (e, data)
var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if (href != '#') iframe.src = href;
else $(this).jstree('toggle_node', data.node);

).on('ready.jstree', function (e, data)
var leaf = null;
var getFirstLeaf = function (id)
var node = data.instance.get_node(id);
if(node.children.length > 0)
return getFirstLeaf(node.children[0]);

return data.instance.select_node(id); //Triggers select_node event
;
getFirstLeaf('phtml_1'); // Start from the root node id
);





share|improve this answer















You can use the ready.jstree event handler to select a node after the tree is ready. The select_node function on the tree instance will trigger the select_node event.



$('#songchanges').jstree(

'plugins': ['themes', 'html_data', 'ui', 'cookie'],
'core': 'initially_open': ['phtml_1']

).on('select_node.jstree',
function (e, data)
var href = data.node.a_attr.href;
var iframe = document.getElementById("processingResults");
if (href != '#') iframe.src = href;
else $(this).jstree('toggle_node', data.node);

).on('ready.jstree', function (e, data)
var leaf = null;
var getFirstLeaf = function (id)
var node = data.instance.get_node(id);
if(node.children.length > 0)
return getFirstLeaf(node.children[0]);

return data.instance.select_node(id); //Triggers select_node event
;
getFirstLeaf('phtml_1'); // Start from the root node id
);






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 29 at 6:28

























answered Mar 28 at 14:14









Stephen SStephen S

2,6482 gold badges13 silver badges24 bronze badges




2,6482 gold badges13 silver badges24 bronze badges















  • HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

    – Paul Taylor
    Mar 28 at 15:27












  • I've updated the code to traverse and select a leaf node.

    – Stephen S
    Mar 28 at 16:23











  • Great that works, if I change last line to getFirstLeaf('phtml_1');

    – Paul Taylor
    Mar 28 at 20:32











  • Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

    – Stephen S
    Mar 29 at 3:46

















  • HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

    – Paul Taylor
    Mar 28 at 15:27












  • I've updated the code to traverse and select a leaf node.

    – Stephen S
    Mar 28 at 16:23











  • Great that works, if I change last line to getFirstLeaf('phtml_1');

    – Paul Taylor
    Mar 28 at 20:32











  • Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

    – Stephen S
    Mar 29 at 3:46
















HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

– Paul Taylor
Mar 28 at 15:27






HI, thank that helps but doesn't work yet. Any non-leaf node would have href='#' not just root, but the root node does always have an id of phtml_1. Your code is causing root to open to show leaf node, but is not triggering select node function for that leaf node ?

– Paul Taylor
Mar 28 at 15:27














I've updated the code to traverse and select a leaf node.

– Stephen S
Mar 28 at 16:23





I've updated the code to traverse and select a leaf node.

– Stephen S
Mar 28 at 16:23













Great that works, if I change last line to getFirstLeaf('phtml_1');

– Paul Taylor
Mar 28 at 20:32





Great that works, if I change last line to getFirstLeaf('phtml_1');

– Paul Taylor
Mar 28 at 20:32













Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

– Stephen S
Mar 29 at 3:46





Yeah, it should be set to the root node's id. In most cases it is # so I've assumed it as such in the answer

– Stephen S
Mar 29 at 3:46








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346118%2fhow-do-i-get-jstree-to-automatically-open-path-to-the-first-tree-node-and-trigg%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript