Element.querySelector

« Gecko DOM Reference

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(selectors);

where

  • element and baseElement are element objects.
  • selectors is a group of selectors to match on.

Example

In this example, the first style element which either has no type or has type text/css in the HTML document body is returned:

var el = document.body.querySelector("style[type='text/css'], style:not([type])");

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.

querySelector() was introduced in the WebApps API.

Browser compatibility

Browser Support Notes
Internet Explorer 8  
Firefox (Gecko) 3.5 (1.9.1)  
Opera 10  
Chrome 1  
Safari (webkit) 3.2 (525.3) webk.it/16587

Specification

Tags (0)

Edit tags
  • No tags

Attachments (0)

 

Attach file