jQuery - Finding next Div

前端 未结 5 1300
逝去的感伤
逝去的感伤 2021-02-13 12:47

I am trying to find the next div after an input button and toggle it.

What am I doing wrong?

JS:

$(\".showNextExperience\").click(function() {
          


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-13 13:04

    Assuming you have elements between triggering input and manipulated div:

    
    

    Hello, new line

    Experience 1

    Some text

    And an info block
    Experience 2

    Then you have to use nextAll to search not only for the very next element but through the whole DOM, which is probably simpler coding than using next().find():

    $(".showNextExperience").click(function() {
        $(this).nextAll(".experience").toggle();
    });
    

提交回复
热议问题