I'm pretty new to jquery and I have what is likely a very simple problem.
I'm trying to implement a flyout menu for navigation on a new site, and because of the limitations put on me by my CMS, I'm unable to add classes to the <ul>
's to which the flyout functionality will be applied.
For example:
Change this:
<div class="SideCategoryListClassic">
<ul **class="fancynav"**>
<li class=""><a href="http://blah.com/categories/product/">Product</a>
<ul>
<li class="LastChild">
<a href="http://blah.com/categories/product/Accessories/">Accessories</a>
</li>
</ul>
</li>
</ul>
<ul **class="fancynav"**>
<li class=""><a href="http://blah.com/categories/product/">Product</a>
<ul>
<li class="LastChild">
<a href="http://blah.com/categories/product/Accessories/">Accessories</a>
</li>
</ul>
</li>
</ul>
To this:
<div class="SideCategoryListClassic">
<ul>
<li class=""><a href="http://blah.com/categories/product/">Product</a>
<ul>
<li class="LastChild">
<a href="http://blah.com/categories/product/Accessories/">Accessories</a>
</li>
</ul>
</li>
</ul>
<ul>
<li class=""><a href="http://blah.com/categories/product/">Product</a>
<ul>
<li class="LastChild">
<a href="http://blah.com/categories/product/Accessories/">Accessories</a>
</li>
</ul>
</li>
</ul>
Again, sure it's simple but I'm not sure how to only grab those top level <ul>
's without get开发者_如何学Pythonting the ones nested within them.
$(".SideCategoryListClassic > ul")
This gets only ul
s that are direct children of .SideCategoryListClassic
I think what you want is something like the following ...
$(".SideCategoryListClassic").children("ul").addClass("myClass");
the children("ul")
bit will only get the top level <ul>
tags
精彩评论