简体   繁体   中英

remove active class on click of different row of tabs jQuery ui

$(document).ready(function() {
    $('.tabs .tab-links a').on('click', function(e)  {
        var currentAttrValue = $(this).attr('href');

        // Show/Hide Tabs
        $('.tab').slideUp();
        $('.tabs ' + currentAttrValue).slideDown(); // causes slide up if click on other tab


        // Change/remove current tab to active
        $(this).parent('li').addClass('active').siblings().removeClass('active');

        e.preventDefault();
    });
});

what I'm trying to do is remove the active class once I click on another tab in a different row, at the moment it's set to remove the class if I click on another tab in the same row I need this to be applied to all rows.

The active class is used in my CSS to give a different background colour, at the moment when I click on tab 3 (for example) then tab 4 three will no longer have a background colour but 4 will perfect.

But now I have multiple rows of tabs and if I click again on row 1 tab 2 then click on row 2 tab 1 then the first tab I clicked on ( row 1 tab 2) still has a active class so still has a different background colour.

It's a problem I have had now for 2 days, if anyone knows how to solve please help. Than you.

I did a fiddle:

http://jsfiddle.net/fzvyu63w/


$('.tab').on('click', function(){

    var thisTab = this;

    /* some code ... */

    /* Removing active effect with slideUp: */
    $('.active').not(thisTab).slideUp(function(){
        $(this).removeClass('active').fadeIn();
    });

    /* After that, active the clicked tab: */
    $(thisTab).addClass('active');

});

Try this

$('.tabs').removeClass('active').slideUp();

OR

$(".active").removeClass("active");

Solved

//Change/remove current tab to active
$("li").click(function() {
   $('li').removeClass("active");
   $(this).addClass("active");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM