javascript - jQuery add variable to selector not working -


i passing id selector, somehow doesn't work. when hardcode it, works. below script , various ways have tried. :

 jquery("li.<?php echo slugify($catid); ?>").closest("ul").closest("li").addclass("active");     

when view in console, script above echoes out $catid correctly doesn't work. tried :-

var catid='<?php echo $catid; ?>'; jquery("li."+catid).closest("ul").closest("li").addclass("active"); 

in console, variable catid wasn't printed out @ all. shows ("li."+catid) in console.

then tried converting string , pass selector :

var catstring = catid.tostring();  

it doesn't work either. hardcode catid directly line , works fine.

anyone can help? in advance.

if trying above snippets html should this

<li class="<?php echo slugify($catid); ?>"> .... 

and shouldn't associating them id attribute


Comments