Skip to content

Instantly share code, notes, and snippets.

@eligrey
Last active July 11, 2023 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eligrey/f109a6d0bf4efe3461201c3d7b745e8f to your computer and use it in GitHub Desktop.
Save eligrey/f109a6d0bf4efe3461201c3d7b745e8f to your computer and use it in GitHub Desktop.
Node.isConnected polyfill for EdgeHTML
/*
* 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
)
);
},
});
}
@vanowm
Copy link

vanowm commented Dec 26, 2022

Wouldn't a connected element always have a parentNode? (unless of course it's a root element)

@theseer
Copy link

theseer commented Jul 11, 2023

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