Node isConnected
Publikováno: 13.11.2020
Every so often I discover a property in JavaScript objects that I didn’t know existed, oftentimes using another trick to accomplish the same functionality. One such property I just learned about was isConnected, a node property that attached to a context (i.e. document). Here’s how to use Node.prototype.isConnected: const el = document.createElement('div'); el.isConnected; // false […]
The post Node isConnected appeared first on David Walsh Blog.
Every so often I discover a property in JavaScript objects that I didn’t know existed, oftentimes using another trick to accomplish the same functionality. One such property I just learned about was isConnected, a node property that attached to a context (i.e. document).
Here’s how to use Node.prototype.isConnected:
const el = document.createElement('div');
el.isConnected; // false
document.body.appendChild(el);
el.isConnected; // true
I used to run parentNode checks on the element to see if it had been injected but that’s not always accurate, so I’m glad isConnected exists!
The post Node isConnected appeared first on David Walsh Blog.