Reputation:
It is said, in many many places, that they're both the same thing. But when they start explaining they refer to each one of them differently without giving a clear explanation about what's the difference?
Please try to be as specific as possible as I'm still learning JS not really great with it yet. :)
Upvotes: 2
Views: 4078
Reputation: 21
all element is node but node not all element,element and node all are object type.
Upvotes: 0
Reputation: 9782
A Node is an interface from which a number of DOM types inherit, and allows these various types to be treated (or tested) similarly. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Node
The Element interface represents an object of a Document. This interface describes methods and properties common to all kinds of elements. Specific behaviors are described in interfaces which inherit from Element but add additional functionality. For example, the HTMLElement interface is the base interface for HTML elements, while the SVGElement interface is the basis for all SVG elements. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Element
An object may represent anything. Objects have properties, which describe them, and methods which are actions that can be performed on them.
Putting it together:
You can create a DOM Node in a web page like so:
var node=document.createTextNode('A Node');
Then you can create a paragraph element:
var p=document.createElement('p');
Attach the node to the paragraph:
p.appendChild(node);
You may also reference the node and element as objects:
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
Upvotes: 3