Try this:
$('#home').click(function () {
var roots = $('#tree').jstree(true).get_children_dom($('#tree'));
roots.each(function(x, k) { alert(k.id); });
});
In the function each
, you get the IDs of the root nodes, so you should add your code there.
If you want the text of the root nodes, you can use the function get_text
for each nodes that we identified before:
$('#home').click(function () {
var tree = $('#tree').jstree(true);
var roots = tree.get_children_dom($('#tree'));
roots.each(function(x, k) {
alert(tree.get_text($('#'+k.id)));
});
});
Code in Fiddle: http://jsfiddle.net/fuu94/41/