Retrieving a Single Element with the WinJS.Utilities.id() Method

If you want to retrieve a single element from a document, instead of matching a set of elements, then you can use the WinJS.Utilities.id() method. For example, the following line of code changes the background color of an element to the color red:

WinJS.Utilities.id("message").setStyle("background-color", "red");

The statement matches the one and only element with an id of message. For example, the statement matches the following DIV element:

<div id="message">Hello!</div>

Notice that you do not use a hash when matching a single element with the WinJS.Utilities.id() method. You would need to use a hash when using the

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.