Use ownerDocument.contains() to detect removed nodes (if available)
Use compareDocumentPosition() instead of parentNode check
(Firefox 8 and older)