Node isConnected

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.


This content originally appeared on David Walsh Blog and was authored by David Walsh

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.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2020-11-13T15:55:55+00:00) Node isConnected. Retrieved from https://www.scien.cx/2020/11/13/node-isconnected/

MLA
" » Node isConnected." David Walsh | Sciencx - Friday November 13, 2020, https://www.scien.cx/2020/11/13/node-isconnected/
HARVARD
David Walsh | Sciencx Friday November 13, 2020 » Node isConnected., viewed ,<https://www.scien.cx/2020/11/13/node-isconnected/>
VANCOUVER
David Walsh | Sciencx - » Node isConnected. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/11/13/node-isconnected/
CHICAGO
" » Node isConnected." David Walsh | Sciencx - Accessed . https://www.scien.cx/2020/11/13/node-isconnected/
IEEE
" » Node isConnected." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2020/11/13/node-isconnected/. [Accessed: ]
rf:citation
» Node isConnected | David Walsh | Sciencx | https://www.scien.cx/2020/11/13/node-isconnected/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.