[英]listener if element was added to DOM
I am fully aware of MutationObserver
but what I need is different: 我完全了解
MutationObserver
但我需要的是不同的:
I would like to listen to an element which has been created in the memory, and that specific element can be appended anywhere (thus I do not want to observe everything because it would be an overkill as things gets changed everywhere on the app, all the time). 我想听一个已经在内存中创建的元素,并且该特定元素可以被附加到任何地方(因此我不想观察所有内容,因为随着应用程序各处的内容发生变化,这将是一种过度杀伤,所有时间)。
The listener would fire when the specific element has been inserted to the DOM. 当特定元素已插入DOM时,侦听器将触发。 just a way to follow a single element instead of watching the whole DOM.
只是一种跟踪单个元素而不是观察整个DOM的方法。 it's kinda backwards approach but I think it is the right way to go in my case.
这有点倒退,但我认为这是我的理由。
How can this be done? 如何才能做到这一点? thanks!
谢谢!
$myobject.appendTo('body').trigger('myobserver');
$myobject.on('myobserver',function(){
//do stuff when myobject is added to DOM
});
You could use this CSS trick too: http://www.backalleycoder.com/2012/04/25/i-want-a-damnodeinserted/ 你也可以使用这个CSS技巧: http : //www.backalleycoder.com/2012/04/25/i-want-a-damnodeinserted/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.