Element.querySelectorAll

  • Revision slug: DOM/Element.querySelectorAll
  • Revision title: Element.querySelectorAll
  • Revision id: 37112
  • Created:
  • Creator: ebidel
  • Is current revision? No
  • Comment 1 words added

Revision Content

{{ DomRef() }}

Summary

Returns a non-live NodeList of all elements descended from the element on which it is invoked that match the specified group of CSS selectors.

Syntax

elementList = baseElement.querySelectorAll(selectors);

where

  • elementList is a non-live list of element objects.
  • baseElement is an element object.
  • selectors is a group of selectors to match on.

Examples

This example returns a list of all the p elements in the HTML document body:

var matches = document.body.querySelectorAll('p'); 

This example returns a list of p children elements whose parent is a div that contains the class 'highlighted':

var matches = document.querySelectorAll('div.highlighted > p'); 

This example returns a list of iframe elements that contain a data attribute 'src':

var matches = document.querySelectorAll('iframe[data-src]'); 

Notes

Throws a SYNTAX_ERR exception if the specified group of selectors is invalid.

querySelectorAll() was introduced in the WebApps API.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1 3.5 (1.9.1) 8 10 3.2 (525.3)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support yes {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} yes

Specification

See also

Revision Source

<p>{{ DomRef() }}</p>
<p>Summary</p>
<p>Returns a non-live <a href="/En/DOM/NodeList" title="En/DOM/NodeList"><code>NodeList</code></a> of all elements descended from the element on which it is invoked that match the specified group of CSS selectors.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><em>elementList</em> = baseElement.querySelectorAll(<em>selectors</em>);
</pre>
<p>where</p>
<ul> <li><code>elementList</code> is a non-live list of <a class="internal" href="/en/DOM/element" title="En/DOM/Element">element</a> objects.</li> <li><code>baseElement</code> is an <a href="/en/DOM/element" title="en/DOM/element">element</a> object.</li> <li><code>selectors</code> is a group of selectors to match on.</li>
</ul>
<h3 name="Example">Examples</h3>
<p>This example returns a list of all the <code>p</code> elements in the HTML document body:</p>
<pre class="brush: js">var matches = document.body.querySelectorAll('p'); 
</pre>
<p>This example returns a list of <code>p</code> children elements whose parent is a <code>div</code> that contains the class 'highlighted':</p>
<pre class="brush: js">var matches = document.querySelectorAll('div.highlighted &gt; p'); 
</pre>
<p>This example returns a list of <code>iframe</code> elements that contain a <strong>data</strong> attribute 'src':</p>
<pre class="brush: js">var matches = document.querySelectorAll('iframe[data-src]'); 
</pre>
<h3 name="Notes">Notes</h3>
<p>Throws a <code>SYNTAX_ERR</code> exception if the specified group of selectors is invalid.</p>
<p><code>querySelectorAll()</code> was introduced in the WebApps API.</p>
<h3>Browser compatibility</h3>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>1</td> <td>3.5 (1.9.1)</td> <td>8</td> <td>10</td> <td>3.2 (525.3)</td> </tr> </tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>yes</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>yes</td> </tr> </tbody>
</table>
<h3 name="Specification">Specification</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/selectors-api/" title="http://www.w3.org/TR/selectors-api/">Selectors API</a></li>
</ul>
<h3 name="See_also">See also</h3>
<ul> <li>{{ DOMMeth("querySelector") }}</li> <li><a class="internal" href="/En/DOM/Document.querySelectorAll" title="en/DOM/document.querySelectorAll"><code>document.querySelectorAll</code></a></li> <li><a class="internal" href="/En/DOM/Document.querySelector" title="en/DOM/document.querySelector"><code>document.querySelector</code></a></li> <li><code><a href="/En/Code_snippets/QuerySelector" title="En/Code_snippets/QuerySelector">Code snippets for querySelector</a></code></li>
</ul>
</div>
Revert to this revision