Back

The querySelectorAll Method

About

The querySelectorAll and querySelector methods are defined on document and HTMLElement objects. With querySelectorAll, you pass it a CSS selector and it returns a list of elements in the document (or in the HTMLElement it is called on) which match the selector.

With querySelector, the behavior is identical, except that instead of returning a list, it returns only the first element which matches the selector (or null, if there were no matched elements).

This behavior is nearly identical to the selector engine feature of jQuery. These methods are part of the W3C Selectors API.

References:

  1. http://www.w3.org/TR/selectors-api2/#queryscopedselector
  2. https://developer.mozilla.org/en/DOM/Document.querySelectorAll