JavaScript is partly an object-oriented language.

To learn JavaScript, we got to learn the object-oriented parts of JavaScript.

In this article, we’ll look at the DOM.

Accessing DOM Nodes

We can access DOM nodes with built-in objects in the browser.

The document node gives us access to the current document.

We can see the properties of it with the console.dir method:

console.dir(document);

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.

The:

document.nodeType;

returns 9.

There’re 12 node types, which are represented by integers.

The most common is 1 for element, 2 attributes, and 3 for text.

document.nodeName

returns '#document' .

And document.nodeValue is null .

documentElement

The document.documentElement property gives us the HTML element.

The nodeType is 1 since it’s an element.

We can see that with:

document.documentElement.nodeType

We can get the nodeName with:

document.documentElement.nodeName

and get the tag name with:

document.documentElement.tagName

They both return 'HTML' .

#technology #programming #javascript

Object-Oriented JavaScript — DOM Traversal
1.35 GEEK