A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/css/selectors_api/querySelector below:

querySelector · WebPlatform Docs

querySelector Summary

Returns the first element that matches the provided selector.

Method of dom/Elementdom/Element

Syntax
var element = element.querySelector();
Parameters selectors
Data-type
String

A selector, or multiple selectors (separated by commas).

Return Value

Returns an object of type DOM NodeDOM Node

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

Examples

This example illustrates how the selectors in the selector string are scoped to the entire document. The variable e contains the span even though the provided selector references the P element, which is outside the scope of the starting DIV element.

<!doctype html>
<html>


<body>
    <p>
        <div id="apple">
        Some are sauce, some are pie.
        </div>
    </p>
<script>
    var div = document.getElementById("apple");
    var   e = div.querySelector("p span");    
    var   f = div.querySelector("p div");     
</script>
</body>
</html>
Notes

The document search order is depth-first. This method returns the first element found. To find all matching nodes, use 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. Calling this method with an unknown selector (due to the browser not implementing it, or due to typo and such) may throw an exception.

Related specifications
Selectors API Level 1
Proposed Recommendation
See also Related pages Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4