nikospap
nikospap

Reputation: 211

jquery accordion click toggle class

i want in this when tab slide up remove class active and add active class in open tab

 $(document).ready(function(){
            $("#accordian li h3").click(function(){
                //slide up all the link lists
                $("#accordian ul .row").slideUp();
                //slide down the link list below the h3 clicked - only if its closed
                if(!$(this).next().is(":visible"))
                {
                    $(this).next().slideDown();

                }
            })
        })

Upvotes: 0

Views: 3797

Answers (3)

A. Wolff
A. Wolff

Reputation: 74420

 $(document).ready(function () {
     $("#accordian li h3").click(function () {
         var $parent = $(this).parent();
         if ($parent.hasClass('active')) return;
         //slide up all the link lists
         $("#accordian ul .row").slideUp();
         $(this).next().slideDown(function () {
             $parent.addClass('active').siblings().removeClass('active');
         });
     })
 })

DEMO

Upvotes: 1

Ravi Gadag
Ravi Gadag

Reputation: 15861

first remove all active class. then add to the current clicked one's. Demo: Accordion

$('#accordian li').removeClass('active');
$(this).parent('li').addClass('active');

Upvotes: 1

Anton
Anton

Reputation: 32581

Something like this?

$(this).parent().addClass('active').siblings().removeClass('active');

DEMO

Upvotes: 1

Related Questions