add class to parent li if Child element is actve
I have searched all over but can't seem to figure how to do this. I have a
menu that has sub navigation in. I want to be able to highlight the parent
li when the child li is selected. I have figured out how to get the child
selected but not the parent. Please help.
Javascript
$('.nav a').each(function (index) {
if (this.href.trim() == window.location)
$(this).addClass("selected");
});
Html
<ul class="nav">
<li><a id="A2" href="~/" runat="server">HOME</a></li>
<li><a href="/about.aspx">ABOUT US</a></li>
<li class="dropdown"><a href="#contact" role="button"
class="dropdown-toggle" data-toggle="dropdown">PRODUCTS</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/products-access-control.aspx">Product
1</a></li>
<li><a href="/products-time-attendance.aspx">Product
2</a></li>
<li><a href="/products-service.aspx">Product 3</a></li>
<li><a href="/partner-solutions.aspx">Product
4</a></li>
</ul>
</li>
<li><a href="#" ID="newslink1" runat="server">NEWS</a></li>
<li><a href="/contact.aspx">CONTACT US</a></li>
</ul>
No comments:
Post a Comment