Subscribe to our YouTube Channel for more Videos

How to Get an Single Element from a document in WinJS Library ?

If you want to get the single element from a document in a Windows Store App developed using WinJS library , the developers can utilize the method.

How to Get an Single Element from a document in WinJS Library ?

Below is a sample code snippet demonstrating how to retrieve the element from the current document using the method.

<script type="text/javascript">"Message").setStyle("color", "Yellow");


The above statement identifies the element “Message” and sets its foreground color to Yellow .

Note that we can also use the WinJS.Utilities.query method to perform the same operation as above. Below is the code snippet demonstrating the usage of Query method.

<script type="text/javascript">
        WinJS.Utilities.query("Message").setStyle("color", "Yellow");

Here’s the complete HTML page that is used in this sample.

<!DOCTYPE html>
    <meta charset="utf-8" />

    <! – WinJS references – >
    <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.2.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.2.0/js/ui.js"></script>

    <script src="Scripts/jquery-2.1.1.js"></script>
    <! – WinJSApp references – >
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
    <style type="text/css">
        #Message {
    <div id="Message">
        This is a Welcome Message
    <button id="btnDisplay">
        Click Me
    <script type="text/javascript">"Message").setStyle("color", "Yellow");

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.