Possible Duplicate:
Most efficient method of detecting/monitoring DOM changes?
I tried this, but it doesn't works:
HTMLElement.prototype.onload = function() {
alert(this.tagName);
};
Possible Duplicate:
Most efficient method of detecting/monitoring DOM changes?
I tried this, but it doesn't works:
HTMLElement.prototype.onload = function() {
alert(this.tagName);
};
Elements don't appear in documents unless you put them there.
Mutation events exist to trap inserts, deletes, etc, but they're not well supported so most of the time you're better off just trapping the insertions at the time you do them.
Really, what are you trying to achieve here?
If it is only about to determine if a given HTMLElement is currently in the DOM you can refer to the element's parentNode
attribute. All elements except <html>
will have a parentNode when they are part of the DOM tree. And you can have elements that you created via JS but never inserted into the DOM or elements that were in the DOM but now are removed from it. Either way, one with parentNode IS currently in the DOM and one w/o is not.