示例:
http://jsfiddle.net/qKMH8/141/
如果我删除.next(),它当然有效,但它会切换每个答案。我只想要那个特定部分的那个切换。有什么想法吗?
$(document).ready(function () {
$('.question').click(function () {
$(this).next('.answer').toggle();
});
});
<section class="question active">
<header>
<h2>What can I create a fundraising campaign for?</h2>
<i class="fa fa-minus-circle"></i>
</header>
<p class="answer">We allow campaigns of almost any nature, however, the following are excluded: Child beauty pageants, pornography, racist content, some religious themes, and illegal activity. If you have a question about what you can fundraise for, please contact us here.</p>
</section>
<section class="question">
<header>
<h2><a href="#">What can I create a fundraising campaign for?</a></h2>
<a href="#" class="fa fa-plus-circle"></a>
</header>
<p class="answer">We allow campaigns of almost any nature, however, the following are excluded: Child beauty pageants, pornography, racist content, some religious themes, and illegal activity. If you have a question about what you can fundraise for, please contact us here.</p>
</section>
<section class="question">
<header>
<h2><a href="#">What can I create a fundraising campaign for?</a></h2>
<a href="#" class="fa fa-plus-circle"></a>
</header>
<p class="answer">We allow campaigns of almost any nature, however, the following are excluded: Child beauty pageants, pornography, racist content, some religious themes, and illegal activity. If you have a question about what you can fundraise for, please contact us here.</p>
</section>
<section class="question">
<header>
<h2><a href="#">What can I create a fundraising campaign for?</a></h2>
<a href="#" class="fa fa-plus-circle"></a>
</header>
<p class="answer">We allow campaigns of almost any nature, however, the following are excluded: Child beauty pageants, pornography, racist content, some religious themes, and illegal activity. If you have a question about what you can fundraise for, please contact us here.</p>
</section>
<section class="question">
<header>
<h2><a href="#">What can I create a fundraising campaign for?</a></h2>
<a href="#" class="fa fa-plus-circle"></a>
</header>
<p class="answer">We allow campaigns of almost any nature, however, the following are excluded: Child beauty pageants, pornography, racist content, some religious themes, and illegal activity. If you have a question about what you can fundraise for, please contact us here.</p>
</section>
答案 0 :(得分:4)
$(this).find('.answer').toggle();