jquery remove parent not working on dynamically created divs

后端 未结 3 1728
傲寒
傲寒 2021-02-14 12:06

im trying to use jquery in order to make a button remove its parent div.

my markup:

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-14 13:04

    Use a delegated handler (on) with the class as the selector so that any new buttons that get added later will still work.

    $('body').on('click', '.button_remove_web_store', function() {
        $(this).parents("div:first").remove();
    });
    

提交回复
热议问题