【发布时间】:2019-04-28 00:54:08
【问题描述】:
我有一个手风琴的 Jquery 代码,它运行良好,除了我需要在活动触发器上添加/删除类。我的意思是,当点击 H2 元素时,我需要添加一个“手风琴切换”类。此处显示的代码在切换时将类添加到所有 H2 元素,我只需要将其添加到活动 H2。
我可以在这方面寻求帮助。
$(document).ready(function(){
$('div.accordion-content> p').hide();
$('div.accordion-content> h2').click(function() {
$(this).next('p').slideToggle('fast')
.siblings('p:visible').slideUp('fast');
$('div.accordion-content> h2').toggleClass('accordion-toggled');
});
});
HTML
<div class="accordion-content">
<h2>Question 1</h2>
<p>Some answers for question 1</p>
<h2>Question 2</h2>
<p>Some answers for question 2</p>
<h2>Question 3</h2>
<p>Some answers for question 3</p>
</div>
【问题讨论】:
标签: jquery accordion slidetoggle