Web/API/ParentNode/querySelector

From Get docs

Draft This page is not complete.


The ParentNode mixin defines the querySelector() method as returning an Element representing the first element matching the specified group of selectors which are descendants of the object on which the method was called.

If you need all the elements matching the selector list, use querySelectorAll() instead.

Syntax

element = parentNode.querySelector(selectors);

Parameters

selectors
A DOMString containing one or more selectors to match against. This string must be a valid compound selector list supported by the browser; if it's not, a SyntaxError exception is thrown. See Locating DOM elements using selectors for more information about using selectors to identify elements. Multiple selectors may be specified by separating them using commas.

Note: Characters which are not part of standard CSS syntax must be escaped using a backslash character. Since JavaScript also uses backspace escaping, special care must be taken when writing string literals using these characters. See Escaping special characters for more information.


Return value

The first Element that matches at least one of the specified selectors or null if no such element is found.

Note: If the specified selectors include a CSS pseudo-element, the returned value is always null.


Exceptions

SyntaxError
The syntax of the specified selectors string is not valid.

Specifications

Specification Status Comment
DOMThe definition of 'ParentNode.querySelector()' in that specification. Living Standard Living standard
Selectors API Level 2The definition of 'ParentNode.querySelector()' in that specification. Obsolete No change
DOM4The definition of 'ParentNode.querySelector()' in that specification. Obsolete Initial definition
Selectors API Level 1The definition of 'document.querySelector()' in that specification. Obsolete Original definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
querySelector Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 3.5

IE Full support 9

Notes'

Full support 9

Notes'

Notes' Internet Explorer 8 only supported CSS2 selectors.

Opera

Full support 10

Safari

Full support 4

WebView Android

Full support ≤37

Chrome Android

Full support 18

Firefox Android

Full support Yes

Opera Android

Full support 10.1

Safari iOS

Full support 3.2

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
See implementation notes.'
See implementation notes.


See also