jQuery: clone elements AND events

前端 未结 4 1779
野的像风
野的像风 2021-01-01 17:19

Whenever I use ajax to dynamically create new content, .clone(), append() etc, the new element looses any triggers and events I programmed =(

After making copy, simp

4条回答
  •  抹茶落季
    2021-01-01 17:53

    Hi I'm having a bit similar use case, I have some dynamically generated content that contains a button, click event is responding to the original button but not the generated one, I've done before :

    $('.someclass').on('click', function() {
    

    but i resolved my problem by replacing the on by live like this :

    $('.someclass').live('click', function() {
    

提交回复
热议问题