我想使用 jQuery 选择已添加到 HTML5 内容可编辑 div 的项目。它现在不起作用,因为加载页面时该项目不存在。 如何告诉 jQuery div 已更新?
请查看此 jsfiddle 以获取测试代码:http://jsfiddle.net/kthornbloom/sjHYQ/
$(document).ready(function() {
<!-- This wont work on an image dragged into the div after page load -->
$('#editor img').click(function(){
$(this).fadeOut();
});
});
我看到过其他关于此的问题,但似乎没有一个适用于内容可编辑的 div。
最佳答案
尝试:
$('#editor').on('click', 'img', function() {
$(this).fadeOut();
});
由于您本质上是绑定(bind)一个动态元素,因此您需要使用 .on()
来委托(delegate) #editor
元素上的点击事件,因为没有图像加载页面时在编辑器 div 中。
关于jquery - 如何告诉 jQuery 内容可编辑的 div 已经更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13459928/