1. DOM 是增删改查元素的标准

  1. DOM document object model 文档对象类型 <br /> DOM树是由节点组成的 <br /> 节点的关系:父子兄弟

2.如何获取节点 通过id

  1. var app = document.getElementById("app");<br /> console.log(app);
  1. <script>
  2. <div id="app" class="one">hello</div>
  3. <div>good</div>
  4. <p class="one">world</p>
  5. <script>
  6. var app = document.getElementById("app");
  7. console.log(app);
  8. </script>

3. 如何获取节点 通过class名 tips:获取的是一个集合(类数组对象)

  1. var one = document.getElementsByClassName("one");<br /> console.log(one[0]);
  1. <script>
  2. <div id="app" class="one">hello</div>
  3. <div>good</div>
  4. <p class="one">world</p>
  5. <script>
  6. var one = document.getElementsByClassName("one");
  7. console.log(one[0]);
  8. </script>

4. 如何获取节点 通过标签名获取

  1. var s = document.getElementsByTagName("div");<br /> console.log(s[0])
  1. <script>
  2. <div id="app" class="one">hello</div>
  3. <div>good</div>
  4. <p class="one">world</p>
  5. <script>
  6. var s = document.getElementsByTagName("div");
  7. console.log(s[0])
  8. </script>

5. 如何获取节点 通过选择器去获取

  1. var divs = document.querySelectorAll("body #app");<br /> console.log(divs[0]);
  1. <style>
  2. #app{
  3. color: red;
  4. }
  5. </style>
  6. <script>
  7. <div id="app" class="one">hello</div>
  8. <div>good</div>
  9. <p class="one">world</p>
  10. <script>
  11. var divs = document.querySelectorAll("body #app");
  12. console.log(divs[0]);
  13. </script>