草案
此页面不完整。
ParentNode
mixin defines the
querySelector()
method as returning an
元素
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()
代替。
注意:
This method is implemented as
Document.querySelector()
,
DocumentFragment.querySelector()
and
Element.querySelector()
.
element = parentNode.querySelector(selectors);
selectors
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
使用选择器定位 DOM 元素
for more information about using selectors to identify elements. Multiple selectors may be specified by separating them using commas.
注意: 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 转义特殊字符 了解更多信息。
The first
元素
that matches at least one of the specified selectors or
null
if no such element is found.
注意:
若指定
selectors
include a
CSS pseudo-element
, the returned value is always
null
.
SyntaxError
selectors
string is not valid.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
querySelector
|
Chrome 1 | Edge 12 | Firefox 3.5 |
IE
9
|
Opera 10 | Safari 4 | WebView Android ≤37 | Chrome Android 18 | Firefox Android Yes | Opera Android 10.1 | Safari iOS 3.2 | Samsung Internet Android Yes |
完整支持
见实现注意事项。
querySelector()
Element.querySelector()
,
Document.querySelector()
,和
DocumentFragment.querySelector()
ParentNode
append()
prepend()
querySelector()
querySelectorAll()
replaceChildren()
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument