What is a HTML Node? Step by Step Guide
![]() |
HTML NODE |
Hypertext Markup Language (HTML) has been the standard language for the web communications since its inception.
This basic yet important language comes with a set of features that are important for any developer to understand. One such feature is the HTML node.
What is a Node in HTML?
HTML node is simply an object within the Document Object Model (DOM).
A node in HTML represents everything that is within the HTML document. In fact, it can be said that HTML nodes are the building blocks of DOM.
HTML nodes can be element, attribute, document type, text, comment, or document nodes.
HTML Element Node
This type of node represents HTML elements. They may include <h1>, <p>, <img> and so on and so forth.
Other nodes such as child nodes and text nodes may also fall within the element node.
When using JavaScript, HTML element nodes can be created using document.createElement() method.
When it comes to manipulating these types of nodes, document.querySelector() and document.getElementById() methods are important in such application.
HTML Text Nodes
Text nodes represent the actual text within a HTML element tag.
For example, a paragraph <p> Hello World </p>, the "Hello World" is the text node.
Using JavaScript, a text node can be created using document.createTextNode('Hello World').
HTML Comment Nodes
Comments help in improving the readability of the code and they are not strictly interpreted by the browsers to be displayed.
However, they are stored in the DOM structure. The document.createComment('Comment') method in JavaScript is useful in creating a comment; However, it is rarely used.
HTML Document Node
The Document node sits at the top of the DOM. The document object in JavaScript represents this entire node and it provides methods to interact with each element.
DOCTYPE (Document Type Node)
Doctype <!DOCTYPE html> is a declaration at the beginning of HTML document declaring the version of HTML used.
Also read:
إرسال تعليق