Checking for a class in a Jstree node

217 views
Skip to first unread message

Slim Slam

unread,
Feb 8, 2016, 4:32:53 PM2/8/16
to jsTree
I'm thinking this should be fairly simple but I can't get it to work. I use get_selected() like so:

 var curr_full =  $('#jst_classl').jstree(true).get_selected(true);

And then I want to see if the node has a certain class named "someclass":

var hasSomeClass =   curr_full[0].li_attr.class.hasClass("someclass");

This always yields an error:

TypeError: curr_full[0].li_attr.class.hasClass is not a function. (In 'curr_full[0].li_attr.class.hasClass("someclass")', 'curr_full[0].li_attr.class.hasClass' is undefined)

Any clues?

J

Ger Ald Meier

unread,
Feb 18, 2016, 9:01:50 AM2/18/16
to jsTree
Hi,

Try:


var hasSomeClass =   (curr_full[0].li_attr.hasOwnProperty("class") && curr_full[0].li_attr.class.indexOf("someclass")>=0);

Because curr_full[0].li_attr.class is a string not an jquery object.
Maybe there is some way more elegant but i did not find it either ...
Reply all
Reply to author
Forward
0 new messages