WinJS.Utilities.query function

Applies to Windows and Windows Phone

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 supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS.Utilities

Library

Base.js

 

 

Show:
© 2014 Microsoft. All rights reserved.