JQuery .load() makes content not clickable after load

后端 未结 3 1709
北海茫月
北海茫月 2021-01-23 16:03

I have a page in which I have a div. The content from that div is being populated by an includes page, and that includes page is making a call to a database to retrieve content

3条回答
  •  萌比男神i
    2021-01-23 16:37

    change this line

    $(".newtask").click(function(){
    

    to

    $(document).on(".newtask","click",function(){
    

    or use delegate

    $(document).delegate("click",".newtask",function(){
    

    reason is the dynamically added elements do not get themselves attached to event handlers use on if you are using jQuery 1.7+ else use delegate

提交回复
热议问题