JavaScript does not work after you add new elements

旧时模样 提交于 2019-12-13 05:16:16

问题


JavaScript does not work after you add new elements ? add more later, but I want you to work for elements how to track down a road I do not know Example;

$(".ui-draggable").draggable();    
$('body').append('<div class="ui-draggable"></div>');

回答1:


Because .draggable() is not dynamic.

Do this:

$(".ui-draggable").draggable();    
$('body').append($('<div class="ui-draggable"></div>').draggable());

Your first line attaches only the elements which were present in the DOM.

It will not check for dynamically added ones.



来源:https://stackoverflow.com/questions/23184447/javascript-does-not-work-after-you-add-new-elements

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