javascript element vs node

Solutions on MaxInterview for javascript element vs node by the best coders in the world

showing results for - "javascript element vs node"
Braylon
22 Jul 2017
1/**
2* Node Object: node is the generic name for any type of object in the DOM hierarchy.
3* Element Object: An element is one specific type of node as there are many other types of nodes (text nodes, comment nodes, document nodes, etc...).
4*
5* Types of nodes: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
6* Notes on elements: https://developer.mozilla.org/en-US/docs/Web/API/Element
7*/
8
9console.log(document instanceof Node); // true
10console.log(document instanceof Element); // false
11console.log(document.firstChild); // <html>...</html>
12console.log(document.firstChild instanceof Node); // true
13console.log(document.firstChild instanceof Element); // true
14console.log(document.firstChild.firstChild.nextElementSibling); // <body>...</body>
15console.log(document.firstChild.firstChild.nextElementSibling === document.body); // true
16console.log(document.firstChild.firstChild.nextSibling); // #text
17console.log(document.firstChild.firstChild.nextSibling instanceof Node); // true
18console.log(document.firstChild.firstChild.nextSibling instanceof Element); // false
19console.log(Element.prototype.__proto__ === Node.prototype); // true