HTML Code for menu
<ul id="menu">
<li class="active">
<a href="index.php" >Home</a>
</li>
<li ><a href="about.php" >About us</a></li>
<li ><a href="Contact.php" >Contact us</a></li>
<li ><a href="inquiry.php" >Inquiry</a></li>
</ul>
jQuery code
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#menu li a').each(function(index) {
if(this.href.trim() == window.location)
{
var url1=window.location.pathname.split('/')[2];
$('li.active').removeClass('active');
$('#menu li a[href="'+url1+'"]').parent().addClass('active');
}
});
});
</script>
0 Comments