JQuery .load() makes content not clickable after load

我是研究僧i 提交于 2019-12-02 06:42:15

The jQuery .click event is not a live event, so it will only make items it has been assigned to clickable. Once those items are refreshed, removed or new items come in, the refreshed items won't have the click event and new items won't have the click event.

You'll want to use the jQuery .on event, which is the replacement for the .live event. That way when the contents refresh, they'll still have a click event attached.

The other option is to assign the click event whenever the content refreshes.

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

it will work with this

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

or

$(document).delegate(".newtask","click",function(){
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!