获取元素 document(最顶层)

⭐️ getElementById(document)

<div name='box'></div>
<script>
  var box = document.getElementById('box'); // ie8: div ie8+: null
</script>
<div class="container">
  <div id="id-box" class="class-box1"></div>
</div>
<div id="id-box" class="class-box2"></div>
<script>
  const box = document.getElementById('id-box'); // 小写字母
  const box2 = document.getElementById('Id-Box'); // 大写字母
  console.log(
    box, // 匹配第一个:div#id-box.class-box1
    box2 // null
  ); 
</script>

getElementsByTagName(Document、Element)

<div id="container">
  <p>1</p>
  <p>2</p>
</div>
<p>3</p>
<script>
  const oPList = document.getElementsByTagName('p'); 
  const oContainer = document.getElementById('container');
  const oContainerPList = 
        oContainer.getElementsByTagName('P'); // 1. 元素也能调用 2. 大小写也不敏感
  const oSpanList = document.getElementsByTagName('span');
  console.log(
    oPList, // HTMLConllection(3) [p, p, p]
    oContainerPList, // HTMLConllection(2) [p, p]
    oSpanList, // HTMLConllection []
  );
</script>

**通配符 ***

var all = document.getElementsByTagName('*');
console.log(all);

Untitled

⭐️ getElementsByClassName(Document、Element)