jquery - Need to set the class of a parent div to that of a contained li element -
i'm working on side navigation element needs change color based on menu selected. i'm trying set class of parent div match of li part of menu. here's code:
<div class="cols" id="leftmenuwrapper"> <div id="leftmenu"> <ul id="navsub_657930_721861"> <li class="lmenu_item2"><a href="#">benefits</a></li> </ul> </div> </div>
in example, need set class of "leftmenu" "lmenu_item2". tried jquery didn't work.
$('#leftmenu').addclass($('#leftmenu ul li').class());
i'm assuming issue .class in code above. not sure how grab class li.
thanks in advance help!
you use .attr()
value of attribute want:
$('#leftmenu ul li').attr('classname');
or if part of click handler on <li>
element, can reference 1 clicked this
.
$(this).attr('classname');
Comments
Post a Comment