JavaScript for WordPress Forums Vanilla JavaScript 1.3.04 – Traversing the DOM – Differences between parentElement and parentNode Reply To: 1.3.04 – Traversing the DOM – Differences between parentElement and parentNode

#24977
Zac Gordon
Keymaster

You’re absolutely right Bruno.

In the case of both Text Nodes and Element Nodes, you would only find them inside of other Element Nodes. For this reason getting the parent of any type and the parent element node will always provide the same results.

There may be some edge cases of different node types having different behaviors (I wouldn’t be surprised) but for these two node types on a page it is the case.

Good question