Reputation: 339
How do I get the parent li class in jsTree plugin? Whenever I try to traverse the Javascript tree, I can get to the parent node, but I end up with an object and can never get it to output the parent class as a string, so I can do a simple conditional check against it.
Here's what I want to do:
// JS Tree Event handler for when a node is clicked
$("#dutchData").bind("select_node.jstree", function (e, data) {
// get the parent node class, and then use it in a conditional statement
var parentNodeClass = data.node.parent.attr('class'); // this is wrong, just to demonstrate
if(parentNodeClass != 'x'){
// do something
}
});
Upvotes: 1
Views: 469
Reputation: 5061
That's because the parent
property is not the element but a string id of the element. You can get the parent with jQuery and then get class like so:
$('#'+data.node.parent).attr('class');
Check fiddle: Fiddle
Upvotes: 2