jQuery Highlight Menu Item Of Current Page

<body>
    <ul id="nav">
        <li><a href="home.html">Home</a></li>
        <li><a href="contact.html">Contact</a></li>
    </ul>
</body>
<script type="text/javascript">
$(document).ready(function(){
    $('#nav a').each(function(index) {
        if(this.href.trim() == window.location)
            $(this).addClass("selected");
    });
});
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *