We can traverse the DOM with various properties.
In this article, we’ll look at the DOM.
We can access DOM nodes with built-in objects in the browser.
document node gives us access to the current document.
We can see the properties of it with the
We can use the
nodeType property to get the type of node.
ndoeName has the node’s name.
nodeValue has the value, which is the text for text nodes for example.
There’re 12 node types, which are represented by integers.
The most common is 1 for element, 2 attributes, and 3 for text.
document.documentElement property gives us the HTML element.
nodeType is 1 since it’s an element.
We can see that with:
We can get the
and get the tag name with:
They both return