切换和jQuery的问题

时间:2014-01-06 23:00:51

标签: javascript jquery html

示例:

http://jsfiddle.net/qKMH8/141/

如果我删除.next(),它当然有效,但它会切换每个答案。我只想要那个特定部分的那个切换。有什么想法吗?

的JavaScript:

$(document).ready(function () {
    $('.question').click(function () {
        $(this).next('.answer').toggle();
    });
});

HTML

<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>

1 个答案:

答案 0 :(得分:4)

$(this).find('.answer').toggle();