我想听听另一段将html插入页面的代码。我无法控制该代码,因此无法执行.trigger('custom_event')
和$(document).on('custom_event')
另外,我要听的插入的div嵌套在插入的html中。
这是我现在所拥有的:
$(document).on('DOMNodeInsertedIntoDocument', "#inserted", function () {
console.log("Inserted into document:", $(this));
});
$(document).ready(function () {
var new_node = $('<div><div id="inserted">New Div</div></div>');
$("body").append(new_node);
});
http://jsfiddle.net/AeHxQ/5/
为什么没有触发事件?
最佳答案
您可以将CSS动画与少量JavaScript结合使用,以检测何时将元素添加到DOM。此处说明了该技术:http://davidwalsh.name/detect-node-insertion