Reputation: 130620
I am fully aware of MutationObserver
but what I need is different:
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. just a way to follow a single element instead of watching the whole 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!
Upvotes: 0
Views: 333
Reputation: 74420
$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/
Upvotes: 2