What is the difference between Node / Element / Object?

Many places say they are both the same. But when they begin to explain, they treat each of them differently, without giving a clear explanation of what the difference is?

Please try to be as specific as possible, as I am still involved in JS, but not very good with that. :)

+1
source share
2 answers

A Node is an interface from which several types of DOM are inherited, and allows these various types to be processed (or tested) in a similar way. Link: https://developer.mozilla.org/en-US/docs/Web/API/Node

. , . , Element, . , HTMLElement HTML, SVGElement SVG. : https://developer.mozilla.org/en-US/docs/Web/API/Element

. , , , .

:

DOM Node -, :

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

:

var p=document.createElement('p');

Node :

p.appendChild(node);

Node :

p.className='description';  // set the class property of the paragraph to 'description';

p.setAttribute('data-item', '8');  // add an attribute named data-item with a value of 8
+2

, , .

0

Source: https://habr.com/ru/post/1681026/


All Articles