$(function() {
var pgurl = window.location.href.substr(window.location.href
.lastIndexOf("/") + 1);
$("#nav ul li a").each(function() {
if ($(this).attr("href") == pgurl || $(this).attr("href") == '')
$(this).addClass("active");
});
});
Here is the JavaScript code I am using to add the active class to the list item. It works perfectly, but I want the parent list item to also get an active class when selecting an item within a dropdown list.
<%@include file="header.jsp"%>
<div id="nav">
<ul>
<li class="headerFont"><a href="index.jsp"><b>HOME</b></a></li>
<li class="headerFont"><a href="link.jsp"><b>HOW TO
DONATE</b></a></li>
<li class="headerFont"><a class="tangina" href="#"><b>DONATE</b></a>
<ul>
<li class="headerFont"><a href="link2.jsp"><b>DONATION
CENTER <img id="arrow" src="img/arrow.png" />
</b></a></li>
<li class="headerFont"><a href="link3.jsp"><b>HOW ELSE
CAN I DONATE? <img id="arrow" src="img/arrow.png" />
</b></a></li>
</ul></li>
<li class="headerFont"><a href="#"><b>GET DONORS</b></a></li>
<li class="headerFont"><a href="#"><b>ABOUT BLOOD</b></a>
<ul>
<li class="headerFont"><a href="Bfacts.jsp"><b>BLOOD
FACTS <img id="arrow" src="img/arrow.png" />
</b></a></li>
<li class="headerFont"><a href="news.jsp"><b>NEWS <img
id="arrow" src="img/arrow.png" /></b></a></li>
<li class="headerFont"><a href="faqs.jsp"><b>FAQS <img
id="arrow" src="img/arrow.png" /></b></a></li>
</ul></li>
<li class="headerFont"><a href="about.jsp"><b>ABOUT US</b></a></li>
<li class="headerFont"><a href="login.jsp"><b>LOG IN</b></a>
<ul>
<li class="headerFont"><a href="#"><b>REGISTER <img
id="arrow" src="img/arrow.png" /></b></a></li>
</ul></li>
</ul>
</div>
<div class="triangle"></div>
<div class="triangle2"></div>