Jquery Hide parent div onclick

后端 未结 3 907
鱼传尺愫
鱼传尺愫 2020-12-21 13:54

I want to hide parent div when a child div is clicked.I have appended the div when \"add more\" button is clicked.In short when \"X\" in div is clicked its parent div should

相关标签:
3条回答
  • 2020-12-21 14:09

    you should use deligates for dynamically created items

     $(document).on("click",".delete" function () {
            $(this).parent().hide();
        });
    
    0 讨论(0)
  • 2020-12-21 14:10

    The reason why your code not working is, That element is being appended in to the DOM dynamically, so we have to use event delegation to make the code work..

    Try,

    $(".uploadimg").on("click",".delete",function(){
        $(this).parent().hide();
    });
    

    DEMO

    0 讨论(0)
  • 2020-12-21 14:12

    You need event delegation for dynamically generated DOM:

      $("body").on("click",'.delete',function(){
       $(this).parent().hide();
    });
    

    Working Demo

    0 讨论(0)
提交回复
热议问题