I am using JQuery to create a navigation structure on my web site. This structure is defined by the following code:
<ul id="theMenu">
<li><a title="" href="#"><img alt="Home" src="/dot.png" class="menuHeader" />Home</a></li>
<li><a title="" href="#"><img alt="About" src="/dot.png" class="menuHeader" />About</a>
<ul>
<li><a href="#"><img alt="Our Team" src="/dot.png" class="subMenuHeader" />Our Team</a></li>
<li><a href="#"><img alt="Our Company" src="/dot.png" class="subMenuHeader" />Our Process</a></li>
</ul>
</li>
<li><a title="" href="#"><img alt="Catalog" src="/dot.png" class="menuHeader" />Catalog</a>
<ul>
<li><a href="#"><img alt="" src="/dot.png" class="subMenuHeader" />Men's Clothing</a></li>
<li><a href="#"><img alt="" src="/dot.png" class="subMenuHeader" />Women's Cloting</a></li>
<li><a href="#"><img alt="" src="/dot.png" class="subMenuHeader" />Kids Clothing</a></li>
</ul>
</li>
<li><a title="Contact Us" href="#" class="btm"><img alt="Contact Us" src="/dot.png" class="menuHeader" />Contact Us</a></li>
</ul>
<script type="text/javascript">
$(document).ready(function () {
$("#theMenu > li > a").not(":first").find("+ ul"开发者_如何学编程).slideUp(1);
$("#theMenu > li > a").click(function () {
$(this).find("+ ul").slideToggle("fast");
});
});
</script>
In some situations, I want to pre-select one of the menu items. Let's pretend that I wanted the "Catalog" menu pre-selected (expanded). How would I do this via JQuery?
Thank you!
With the current markup something like
$("img[alt=Catalog]").parent('a').click();
http://jsfiddle.net/loktar/LLrrV/7/
精彩评论