jquery does not select jquery added element

后端 未结 3 858
傲寒
傲寒 2020-12-22 06:38

So I have a jquery function that does something when class \'ajaxsubnote\' is clicked

$(\'.ajaxsubnote\').click(function(){
     //do something....
})
         


        
3条回答
  •  感情败类
    2020-12-22 07:42

    You should use delegated event method to handle dynamic elements. See below,

    // v--- replace document with closest parent container that exist in DOM
    $(document).on('click', '.ajaxsubnote', function(){
         //do something....
    })
    

    For older versions use delegate,

    // v--- replace document with closest parent container that exist in DOM
    $(document).delegate('.ajaxsubnote', 'click', function(){
         //do something....
    })
    

提交回复
热议问题