ParentNode.querySelector() - Web APIs 编辑

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.

Note: This method is implemented as Document.querySelector(), DocumentFragment.querySelector() and Element.querySelector().

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

SpecificationStatusComment
DOM
The definition of 'ParentNode.querySelector()' in that specification.
Living StandardLiving standard
Selectors API Level 2
The definition of 'ParentNode.querySelector()' in that specification.
ObsoleteNo change
DOM4
The definition of 'ParentNode.querySelector()' in that specification.
ObsoleteInitial definition
Selectors API Level 1
The definition of 'document.querySelector()' in that specification.
ObsoleteOriginal definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:65 次

字数:5624

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文