is Node interface just a concept ? What is the difference between element interface and node interface?

Viewed 206

is Node interface just a concept ? What is the difference between element interface and node interface ? when Programmatically used for i need examples please !!

1 Answers

What’s a node? it is the name of any type of object in the DOM tree. It could be one of the built-in DOM elements such as the document itself, document.head or document.body. A node could be an HTML tag specified in the HTML such as , ,,

or it could be a comment node, text node… In fact, a node is any DOM object and every node has a parent, every node is allowed to have one or more children or even zero children.


What’s an element? An element is a specific type of node, one that can be directly specified in the HTML with an HTML tag and can have properties like an id or a class. can have children, etc.


Nodes vs Elements: Nodes are all the different components that a webpage is made up of and elements are one type of node.

You can create a DOM Node in a web page as follows:

var node=document.createTextNode('A Node');

You can create a paragraph element as follows:

var p=document.createElement('p')

To attach the node to the element:

p.appendChild(node);

ref : https://developer.mozilla.org/en-US/docs/Web/API/Node

Related