简体   繁体   English

将活动类添加到jQuery手风琴

[英]Add Active Class to a jQuery Accordion

I need to add an active class to h2 我需要向h2添加一个活动班

$('.acordeon').on('click','h2',function(){ 
    var t = $(this);
    var tp = t.next();
    var p = t.parent().siblings().find('p');
    tp.slideToggle();
    p.slideUp(); 
});
 var t = $(this);
 t.addClass('active');

Is this what you want? 这是你想要的吗? To add an "active" class on the click event? 要在点击事件上添加“活动”类? I hope this helps. 我希望这有帮助。

If you want to "switch" the active class you can use the toggleClass function. 如果要“切换”活动的类,可以使用toggleClass函数。 It would look like this: 它看起来像这样:

t.toggleClass('active');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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