mvcDecease
mvcDecease

Reputation: 21

when another tab is selected ;preveously selected tab style is remaining activated

I am using simple tab ;created using css.

I have current class to show currently active tab . i am managing using jquery

$(".Tabs").click(function(){

$(this).addClass('current ');

});

This works fine but it does not remove class from previously activated tab . Please help

Upvotes: 1

Views: 37

Answers (3)

A_0
A_0

Reputation: 1004

You can use the following code:

$(".Tabs").click(function(){

$(this).addClass('current');

$(".Tabs").not($(this)).removeClass('current');

});

Upvotes: 1

Florin Pop
Florin Pop

Reputation: 5135

This is because you are not removing the current class from the previous active tab.

You can do this by removing the current class from the previous like follows:

$(".Tabs").click(function(){

$(this).parent().find('current ').removeClass('current');

$(this).addClass('current ');

});

Upvotes: 1

artm
artm

Reputation: 8584

Try removing the class from siblings:

$(".Tabs").click(function(){
    $(this).siblings().removeClass("current").addClass('current');
});

Upvotes: 0

Related Questions