开发者

Jquery: slideToggle() multiple divs independently using one function

开发者 https://www.devze.com 2023-02-28 14:10 出处:网络
Markup: <div> <h3 class = \"trigger\">Heading 1</h3> <ul class = \"toggle\"> <li>Line One</li>

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

精彩评论

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

关注公众号