Answers for "dom node vs element"

3

javascript element vs node

/**
* Node Object: node is the generic name for any type of object in the DOM hierarchy.
* 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...).
*
* Types of nodes: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
* Notes on elements: https://developer.mozilla.org/en-US/docs/Web/API/Element
*/

console.log(document instanceof Node); // true
console.log(document instanceof Element); // false
console.log(document.firstChild); // <html>...</html>
console.log(document.firstChild instanceof Node); // true
console.log(document.firstChild instanceof Element); // true
console.log(document.firstChild.firstChild.nextElementSibling); // <body>...</body>
console.log(document.firstChild.firstChild.nextElementSibling === document.body); // true
console.log(document.firstChild.firstChild.nextSibling); // #text
console.log(document.firstChild.firstChild.nextSibling instanceof Node); // true
console.log(document.firstChild.firstChild.nextSibling instanceof Element); // false
console.log(Element.prototype.__proto__ === Node.prototype); // true
Posted by: Guest on July-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language