Click event for elements added to DOM dynamically

前端 未结 2 1948
Happy的楠姐
Happy的楠姐 2021-01-02 23:33

Before jQuery 1.8 I was able to use .live() to fire when a button was clicked that was dynamically inserted by jquery.

Now, .on() and .bind() both do not work for el

2条回答
  •  难免孤独
    2021-01-02 23:46

    delegate is far efficient than on handler

    $(document).delegate('click', "selector", function() {
        //your stuff
    });
    

提交回复
热议问题