how to show/hide divs when divs are created dynamically

后端 未结 2 1938
遥遥无期
遥遥无期 2021-01-16 04:22

I am developing comment systems with two level of replay to the comments and I have a problem with how to show and hide divs .., because it\'s id\'s are different .., I trie

相关标签:
2条回答
  • 2021-01-16 04:59

    After edited question, i suggest you use div instead of span (because of display inline vs block).

    $("button").click(function () {
        $(".myform").toggle('slow');
    });
    

    would do the job how you want.Here is the result.

    0 讨论(0)
  • 2021-01-16 05:20

    As there is no button in your HTML, it's partly a guess. But the following code will toggle the visibility of the span immediately following your button :

     $(document.body).on("click", "button", function () {
          $(this).next("span").toggle();
     });
    

    Note that you'd better define some classes to make the selector more selective :

     $(document.body).on("click", "button.toggler", function () {
          $(this).next("span").toggle();
     });
    
    0 讨论(0)
提交回复
热议问题