Element.querySelector

この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

Summary

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

Syntax

element = baseElement.querySelector(selectors);
  • 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.

The string argument pass to querySelector must follow the CSS syntax. See document.querySelector for a concrete examples.

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

See also

Document Tags and Contributors

最終更新者: TatumCreative,