为什么QuerySelectorall()返回Nodelist而不是HTMLCollection?

发布于 2025-02-12 20:03:30 字数 407 浏览 2 评论 0原文

我最近在JavaScript中学习了querySelectorall()方法,以及它返回Nodelist对象,该对象包含与特定CSS选择器相匹配的所有元素。

现在,我遇到的混乱是,如果querySelectorall()旨在仅匹配元素节点,为什么它不返回htmlCollection而不是getelementsbybyclassname( )getElementsbytagname()做?

querySelectorall()返回Nodelist实例?是什么

意义也用于选择非元素节点?

I was recently learning about the querySelectorAll() method in JavaScript and the fact that it returns back a NodeList object containing all the elements that match a particular CSS selector.

Now the confusion I have is that if querySelectorAll() is meant to only match element nodes, why doesn't it return back an HTMLCollection instead, like getElementsByClassName() and getElementsByTagName() do?

What's the point of querySelectorAll() returning back a NodeList instance?

Is it the case that querySelectorAll() can be used to select non-element nodes as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文