Friday 21 June 2013

jQuery: Highlighting the Menu Item for the Current Page

jQuery: Highlighting the Menu Item for the Current Page
---------------------------------------------------------------------------------------------
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#subnav a').each(function(index) {
        if(this.href.trim() == window.location)
            $(this).addClass("selected");
    });
});
</script>

<style>
.selected {
    background-color: red;
}
</style>

<body>
    <ul id="subnav">
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
    </ul>
</body>
---------------------------------------------------------------------------------------------

No comments:

Post a Comment