jQuery parent().find() problem

前端 未结 2 1075
傲寒
傲寒 2021-02-20 07:07

HTML

Toggle Comment 1
相关标签:
2条回答
  • 2021-02-20 07:33
    $(function(){
        $('.toggle').click(function() {
            $(this).nextAll('.comment:first').slideToggle();
            return false;
        });
    });
    

    jsFiddle.

    0 讨论(0)
  • 2021-02-20 07:52

    its even simpler, I think, when you clean up your html as well a little bit: (avoid br)

    http://jsfiddle.net/ESM4m/27/

    <div class="comments">
        <a class="toggle" href="Fork#">toggle</a>
        <div class="comment" style="display:none;">
            Comment1
        </div>
        <hr />
        <a class="toggle" href="#">toggle</a>
        <div class="comment" style="display:none;">
            Comment2
        </div>
    </div>
    
    
    
    
    $(function(){
        $('.toggle').click(function() {
            $(this).next().slideToggle();
            return false;
        }); 
    });
    
    0 讨论(0)
提交回复
热议问题