Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

querySelector method

Retrieves the first Document Object Model (DOM) element node from descendants of the starting element node that match any selector within the supplied selector string.

Internet Explorer 8


HRESULT retVal = object.querySelector(v, pel);


v [in]

Type: BSTR

The selector string.

pel [out, retval]

Type: IHTMLElement

A DOM element node, or NULL if the search cannot find an element that matches the selector string.

Return value


If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information


The document search order is depth-first. This method returns the first element found. To find all matching nodes, use IElementSelector::querySelectorAll.

The scope of the returned element node is limited to the descendants of the starting element node. If the starting element is document, the search returns nodes from the entire document.

This method does not return the starting element node. For example, div.querySelector("p div") will never return the DIV element that it starts with.

The pseudo-class selectors :hover, :focus, and :active are supported. Selectors that contain :visited or :link are ignored and no elements are returned.

You can search namespaced elements using a selector syntax based on prefix instead of the namespaceURI, for example "nsPrefix \: element", where "nsPrefix" is the prefix of a given element.

Selectors are described in detail in Understanding CSS Selectors and W3C Selectors.

See also

Other Resources
W3C Selectors API
W3C Selectors



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.