Element.querySelector

  • Revision slug: DOM/Element.querySelector
  • Revision title: Element.querySelector
  • Revision id: 96589
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment page created, 135 words added

Revision Content

{{ DomRef() }}

Summary

Returns the first element that is a descendent of the element on which it is invoked that matches the specified group of selectors.

Syntax

element = baseElement.querySelector(selector[, nsresolver]);

where

  • element and baseElement are element objects.
  • selectors is a group of selectors to match on.
  • nsresolver is an optional NSResolver; if provided, the browser will use it to resolve namespace prefixes or to get the default namespace.  This may be null.

Example

Need an example

Notes

Returns null if no matches are found; otherwise, it returns the first matching element.

Throws a SYNTAX_ERR exception if the specified group of selectors is invalid.  If the namespace can't be resolved, a NAMESPACE_ERR exception is thrown.

querySelector() was introduced in DOM Level 3.

Specification

See also

Revision Source

<p>{{ DomRef() }}</p>
<h3 name="Summary">Summary</h3>
<p>Returns the first element that is a descendent of the element on which it is invoked that matches the specified group of selectors.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><em>element</em> = baseElement.querySelector(<em>selector</em>[, <em>nsresolver</em>]);
</pre>
<p>where</p>
<ul> <li><code>element</code> and <code>baseElement</code> are <a href="/en/DOM/element" title="en/DOM/element">element</a> objects.</li> <li><code>selectors</code> is a group of selectors to match on.</li> <li><code>nsresolver</code> is an optional <code>NSResolver</code>; if provided, the browser will use it to resolve namespace prefixes or to get the default namespace.  This may be <code>null</code>.</li>
</ul>
<h3 name="Example">Example</h3>
<p>Need an example</p>
<h3 name="Notes">Notes</h3>
<p>Returns <code>null</code> if no matches are found; otherwise, it returns the first matching element.</p>
<p>Throws a <code>SYNTAX_ERR</code> exception if the specified group of selectors is invalid.  If the namespace can't be resolved, a <code>NAMESPACE_ERR</code> exception is thrown.</p>
<p><span style="font-family: Courier New;"><span>querySelector()</span></span> was introduced in DOM Level 3.</p>
<h3 name="Specification">Specification</h3>
<ul> <li>DOM Level 2 Core Specification: <a class="external" href="http://www.w3.org/TR/selectors-api/#documentselector" title="http://www.w3.org/TR/selectors-api/#documentselector">querySelector</a> </li>
</ul>
<h3 name="See_also">See also</h3>
<ul> <li><a class="internal" href="/En/DOM/element.querySelectorAll" title="En/DOM/element.querySelectorAll"><code>element.querySelectorAll</code></a></li>
</ul>
Revert to this revision