2

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

Honey
  • 21
  • 1

1 Answers1

1

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

Elabbasy00
  • 628
  • 9
  • 21
  • thank you @elabbasy, actually i read MDN documentation but not clearly understand in depth core of it ? thank again – Honey Jan 30 '21 at 12:07
  • your welcome, This question contains a great answer that might benefit you (https://stackoverflow.com/questions/9979172/difference-between-node-object-and-element-object) – Elabbasy00 Jan 30 '21 at 12:12