Is it possible to add some kind of an event/handler when an element is appended to the DOM...?
.click(), .change(), .keyup() etc. alike...
I need to get the height of an element as soon as it is appended and then set the height to another element
You can override the default append method and cause it to trigger a custom append event. Then bind a handler to an element for that event: http://jsfiddle.net/H8ygx/
(function($) { var origAppend = $.fn.append; $.fn.append = function () { return origAppend.apply(this, arguments).trigger("append"); }; })(jQuery); $("div").bind("append", function() { alert('Hello, world!'); }); $("div").append("<span>");
For that you can use the "DOMSubtreeModified" event. But it has limited compatibility. See: http://www.quirksmode.org/dom/events/#t18
$('#myDiv').live("DOMSubtreeModified", function() { alert('something changed inside #myDiv div'); });
This event handler will work with all standard DOM modifying methods: appendTo(), insertBefore(), insertAfter(), etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With