Blog

Some of my recent posts and ramblings.

Highlighting the current page link using jQuery

Here is a simple code snippet to highlight the current page text using jQuery. You can change the selector to be global as well, just use $("* a")

$("#navigation a").each(function(){
    if (window.location.pathname === $(this).attr('href')) {
        $(this).addClass("current");
        $(this).parent().addClass("current");
    }
});

Leave a Reply

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>