开发者

Jquery: slideToggle() multiple divs independently using one function

Markup:

<div>
    <h3 class = "trigger">Heading 1</h3>
    <ul class = "toggle">
        <li>Line One</li>
        <li>Line Two</li>
        <li>Line Three</li>
    </ul>
</div>
<div>
    <h3 class = "trigger">Heading 2</h3>
    <ul class = 开发者_如何学Go"toggle">
        <li>Line One</li>
        <li>Line Two</li>
        <li>Line Three</li>
    </ul>
</div>

and the JQuery:

$(".toggle").slideUp();
$(".trigger").click(function(){
    $(".toggle").slideToggle("slow");
  });

I'd like to be able to toggle these <ul>s independently. Currently, when either <h3> title is clicked both divs toggle...

code is at: http://jsfiddle.net/CPvCZ/4/


The solution is quite simple:

$(".toggle").slideUp();
$(".trigger").click(function(){
    $(this).next(".toggle").slideToggle("slow");
  });

http://jsfiddle.net/CkTRa/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜