How to remove an element that is added dynamically in Javascript

前端 未结 5 1313
鱼传尺愫
鱼传尺愫 2020-12-28 16:40

I have the following code to create some element:

<
5条回答
  •  萌比男神i
    2020-12-28 17:10

    Because it's dynamic content, you can't bind events like the static content, it will not bind to the elements because they don't appear at the time you bind.

    So you should bind event like this:

    $('#parent').on('click', 'a.remove_block', function(events){
       $(this).parents('div').eq(1).remove();
    });
    

提交回复
热议问题