javascript - How to use jQuery to select this parent? -
i have recursive menu need children items effect parent. in example below, how add "selected" class if of children have "selected" class?
<ul> <li class="administration first"> <a href="/administration.aspx"><span>administration</span></a> <ul> <li class="users first selected"><a href="/administration/users.aspx"><span>users</span></a></li> <li class="forms last"><a href="/administration/forms.aspx"><span>forms</span></a></li> </ul> <div style="clear: both;"></div> </li> <li class="analytics"><a href="/analytics.aspx"><span>analytics</span></a></li> <li class="options"><a href="/options.aspx"><span>options</span></a></li> <li class="system last"><a href="/system.aspx"><span>system</span></a></li> </ul>
use parents method filter parent list elements.
$('li.selected').parents('li').addclass('selected');
Comments
Post a Comment