Jquery events do not work on dynamically appended elements

前端 未结 2 1465
情深已故
情深已故 2020-12-14 10:43

I\'m trying to append new DOM objects to some Div and it works, but somehow - the events that I programmed for these new appended objects do not respond. Why is that?

<
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 11:21

    $(document).ready(function(){
    
     $("#add").click(function(){
         $("#containerDiv").append("

    I should hide as well if you click me

    "); }); $("body").on("click","p", function(){ $(this).hide(); }); });

提交回复
热议问题