Creating Controls Imperatively

In the previous section, I created an instance of the DatePicker control declaratively. I declared the control in the HTML markup of the page.

As an alternative to creating a WinJS control declaratively, you can also create a control imperatively. In other words, you can create the control entirely in your JavaScript code.

Consider the page in Listing 4.3. It contains a DIV element with an id of dateBirthday. This DIV element does not have a data-win-control attribute.

LISTING 4.3 Creating a WinJS Control Imperatively (controlImperative\controlImperative.html)

<!DOCTYPE html><html><head>    <meta charset="utf-8" />    <title>Chapter04</title>    <!-- WinJS references -->    <link

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.