Skip to content

Instantly share code, notes, and snippets.

@ghostcode
Last active August 29, 2015 14:03
Show Gist options
  • Save ghostcode/baee5167014a610ed43b to your computer and use it in GitHub Desktop.
Save ghostcode/baee5167014a610ed43b to your computer and use it in GitHub Desktop.
querySelector和querySelectorAll区别

querySelector 和 querySelectorAll 方法是 W3C Selectors API Level 1 规范中定义的。他们的作用是根据 CSS 选择器规范,便捷定位文档中指定元素。 支持情况:目前几乎主流浏览器均支持了他们。包括 IE8(含) 以上版本、 Firefox、 Chrome、Safari、Opera。

它们俩是有区别的:

  1. querySelector返回满足条件的第一个元素(node),而querySelectorAll返回满足条件的所有元素(nodelist);
  2. 在都没有满足条件的元素情况下:querySelector返回__Null__,而querySelectorAll返回空的数组__[]__;

记住:jquery与它俩是有区别的

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment