다음을 통해 공유


WinJS.Utilities.query function

Returns a QueryCollection with zero or one elements matching the specified selector query.

Syntax

var queryCollection = WinJS.Utilities.query(query, element);

Parameters

  • query
    Type: ****

    The CSS selector to use. See Selectors for more information.

  • element
    Type: DOMElement

    Optional. The root element at which to start the query. If this parameter is omitted, the scope of the query is the entire document.

Return value

Type: QueryCollection

A QueryCollection with zero or one elements matching the specified selector query.

Examples

The following code shows two types of queries. The "win-star" class is added to the elements that represent the stars of the rating.

<div id="div">
  <p class='content'>Here is a sentence</p>
  <p class='content'>Here is a sentence</p>
  <p class='content'>Here is a sentence</p>
  <p class='content'>Here is a sentence</p>
</div>
<script type="text/javascript">

   var div = document.getElementById("div");
   var children = WinJS.Utilities.query(".content");
   var y = children.length;

   children = WinJS.Utilities.query("#div");
   y = children.length;
</script>

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Utilities