Highlight current page in jquery
        Posted  
        
            by 3gwebtrain
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by 3gwebtrain
        
        
        
        Published on 2010-06-02T07:51:17Z
        Indexed on 
            2010/06/02
            8:13 UTC
        
        
        Read the original article
        Hit count: 231
        
Hi,
I have the 12 html pages. and all this pages are loads when the left navigation bar link clicked. in this, i need to add a class to the current link, which is clicked and loaded the page. i tried with this:
$(function(){
    $('#container li a').click(function(){
        $('#container li a').removeClass('current');
        var pathname = (window.location.pathname.match(/[^\/]+$/)[0]);
        var currentPage = $(this).attr('href');
        if(currentPage==pathname){
            $(this).addClass('current');
        }
        else{
            alert('wrong');
        }
       // alert(pathname+' currentPage: '+currentPage);
    })
})
it works, but on page load, the class is removed, i don't know why it's happening..
any help?
© Stack Overflow or respective owner