Last active
July 11, 2023 12:52
-
-
Save eligrey/f109a6d0bf4efe3461201c3d7b745e8f to your computer and use it in GitHub Desktop.
Node.isConnected polyfill for EdgeHTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Node.isConnected polyfill for EdgeHTML | |
* 2021-04-12 | |
* | |
* By Eli Grey, https://eligrey.com | |
* Public domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
if (!('isConnected' in Node.prototype)) { | |
Object.defineProperty(Node.prototype, 'isConnected', { | |
get() { | |
return ( | |
!this.ownerDocument || | |
!( | |
this.ownerDocument.compareDocumentPosition(this) & | |
this.DOCUMENT_POSITION_DISCONNECTED | |
) | |
); | |
}, | |
}); | |
} |
Wouldn't a connected element always have a
parentNode
? (unless of course it's a root element)
Depends on your definition of "connected". If it's a childnode within a subtree that's not connected, it does have a parentNode
- but it's still not "connected" within the Document
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't a connected element always have a
parentNode
? (unless of course it's a root element)