I have a simple drop-down menu:
<ul id="nav" >
<li><a href='/'>Parent One</a>
<ul>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
</ul>
</li>
<li><a href='/'>Parent Two</a>
<ul>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
</ul>
</li>
I need to assign a class to the < li > tag of the parent that is equal to the name of the parent in the < a > tag.
<ul id="nav" >
<li class="ParentOne"><a href='/'>ParentOne</a>
<ul>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
</ul>
</li>
<li class="ParentTwo"><a href='/'>ParentTwo</a>
<ul>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
<li><a href='/'>child</a></li>
</ul>
</li>
I tried this bit of code:
<script language="javascript" type="text/javascript">
$('#navigation ul li a').each(function(index) {
var link = $(this);
$('li', link.parent()).addClass(link.text());
});
</script>
But that applies the class to the children's < li > tag and not the parent < li > - any help would be appreciated. Thanks!