+ 1

Do DOM have grandparent?

Say for example the Dom tree goes: Html Head Title And the head is the parent of title, and html is parent of head. Would this mean html is the grandparent of title or does that not exist :/

11th May 2021, 8:48 AM
Neurobean
Neurobean - avatar
2 Réponses
+ 5
Yes, you could say that. The word "grandparent" doesn't translate to any property or method names in the DOM classes, though. There are properties such as parentNode. To get the title element's grandparent, you could do something like title.parentNode.parentNode assuming title was a variable of type DOMElement.
11th May 2021, 8:56 AM
Josh Greig
Josh Greig - avatar
0
11th May 2021, 8:57 AM
Neurobean
Neurobean - avatar