[HTML5] DOM Nodes Explained

人盡茶涼 提交于 2020-03-17 04:15:26
import './assets/css/style.css';

const app = document.getElementById('app');
app.innerHTML = '<h1>JavaScript DOM</h1>';


// <html>
console.log(document.documentElement);
console.dir(document.documentElement);

// <head>
console.dir(document.head);

// <body>
console.dir(document.body);

// retrieve the constructor name
console.log(document.body.constructor.name);

// looking at the prototype chain
console.log(document.body instanceof HTMLBodyElement);
console.log(document.body instanceof HTMLElement);
console.log(document.body instanceof Element);
console.log(document.body instanceof Node);
console.log(document.body instanceof EventTarget);

/*
  - NodeTypes
  1: Element
  2: Attribute
  3: Text
  4: CDATASection
  5: EntityReference
  6: Entity
  7: ProcessingInstruction
  8: Comment
  9: Document
  10: DocumentType
  11: DocumentFragment
  12: Notation
*/

console.log(document.body.nodeType); // 1
console.log(document.nodeType); // 9

// nodeName for any Node types
console.log(document.nodeName); // #document
// tagName for any Element types
console.log(document.tagName); //undefined

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!