Reputation: 8560
I want something like:
$('.pac-container').whenAddToDom(function(){
console.log('element with class pac-container added to DOM');
//I want to use this added element $(this).doSomethingWithThis();
});
Upvotes: 2
Views: 7474
Reputation: 8560
This is solution to my problem:
$(document).bind('DOMNodeInserted DOMNodeRemoved', function(element){
if($(this).hasClass('pac-container')){
console.log(element.target);
}
});
Upvotes: 1
Reputation: 1550
I would wrap the elements that will be appended in a container and do something like this:
$("html").bind("DOMNodeInserted",function(){
console.log('element with class '+$("#container > *").attr('class') +' added to DOM');
});
Here's a fiddle http://jsfiddle.net/PgAJT/295/
Upvotes: 4