Highlight current page in jquery
- by 3gwebtrain
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?