Javascript: how to tell if a node object has been inserted into a document yet
- by thomasrutter
I'd like to be able to identify whether a given DOM node has been inserted into a document, or part of one, yet, or whether it is fresh out of document.createElement() or similar and has not been placed anywhere.
In most browsers just checking the parentNode works.
if (!node.parentNode) {
// this node is not part of a larger document
}
However, in Internet Explorer it appears that new elements, even right after they've been created with document.createElement() already have a parentNode object (of type DispHTMLDocument??).
Any other nice cross-browser and reliable way?