Quantcast
Viewing all articles
Browse latest Browse all 17

JQuery Script to highlight current page’s navigation link

This is a small script used for highlighting the current page’s navigation link. Here you can also specify the scope by  with your own expression. Here I am adding class “selected” to the navigation link which can be used for styling the link.


Script

$(document).ready(function(){
    $('.sf-menu li a').each(function(index) {
        if((this.pathname.trim() == window.location.pathname))
            $(this).parent().addClass("selected");
    });
});

Or

$('#SideAccountMenu li a').each(function(index) {
	if(this.href.trim() == window.location.href)
		$(this).parent().addClass("selected");
});

CSS

#SideCategoryList .sf-menu li.selected{
    background-color: #e762d5;
}

Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 17

Trending Articles