+ 1
How is parent node property implemented in Java Script?
I'm just curious , as every node in DOM is an object and so is the root element Document, parent node property is what links them to their parents object. How is parent node property implemented in JavaScript ? A simple example code would be helpful...thnx .
2 Answers
+ 2
The parentNode property is simply a reference to the parent. It's not the parent or a copy of it, it is just a 'reference'
https://code.sololearn.com/cTBNNd10GoZi/?ref=app
Of course, here we're talking about references. But most browser engines are implemented in C++, so you can imagine how the the parentNode property is a pointer to the parent.
+ 1
Think of the DOM as a tree where each node is like a branch or leaf. The browser's engine builds and manages this tree, keeping track of how each node is connected to its parent and children.