Toggle next element with jQuery

前端 未结 4 1946
难免孤独
难免孤独 2021-01-20 16:58

I have a problem with the this element (I know how this is working).

I have a lot of that html structure. When I click on the a button, the

4条回答
  •  执念已碎
    2021-01-20 17:28

    Description

    You should use jQuery.parent() and jQuery.next() to get this done. Check out the sample and this jSFiddle Demonstration.

    Sample

    Html

    Toevoegen

    Toevoegen

    jQuery

    $(".button").click(function () {
        var div = $(this).parent().next();
        if(div.is(":visible")) {
            div.hide();
        } else {
            div.fadeIn(450);
        };
    });
    

    More Information

    • jSFiddle Demonstration
    • jQuery.next()
    • jQuery.parent()

提交回复
热议问题