HTMLCollection是元素集合
NodeList是节点集合(即既可以包含元素节点,又可以包含文本节点)
而document.querySelectorAll()方法获取到的是一个一个的Element对象(元素集合),
而不是全部的节点(节点集合),为什么返回的却是NodeList,而不是HTMLCollection呢?
html:
<div id="parent">
<div id="child">
<p class="PElement">Hello</p>
<p class="PElement">JavaScript</p>
</div>
</div>
JavaScript:
var pEles = document.querySelectorAll(".PElement");
console.log(pEles);
在浏览器中运行,得到的将是:
The NodeList object returned by the querySelectorAll() method must be static ([DOM], section 8).