runing function when an div has been added to DOM
HI Guys,
I'm new to jquery and the world of javascript.
I've searched a lot and I haven't been able to find a straight answer on how to
run a function when an object has been added dynamically to the DOM.
I have the bellow example code:
- $('div.s').click(function(){
$('body').append('<div class="new" >000<span>lorem ipsum immet dolor</span></div>');
})
$("div.new").live("load", function() {
var cW = $(this).children('span').innerWidth();
alert(cW);
});
You can also find it here: http://jsfiddle.net/manolis/kG8r2/4/
I have realised that live doesn't work with load. How can I have a function executed when the div is added to the DOM ? custom event maybe?
Thanks a lot! any help is highly appreciated!