addClass problem in jquery with (html) page
I am trying to add a class to li , on click event, but whenever I do that it does add class for a moment then load the page, I have used the following code.
$('.navLi').click(function(){
$(this).addClass('sele开发者_JS百科cted');
});
I wish to selected tab on navigator Li .How I do?
You need to disable the default action:
$('.navLi').click(function(e){
e.preventDefault();
$(this).addClass('selected');
});
See the API.
just return false to disable the default behaviour
$('.navLi').click(function(){
$(this).addClass('selected');
return false;
});
Edit: oh .. hold on, when you click an li it loads the page? is there a link in the li?
精彩评论