Search code examples
javascripthtmlcsswindows-8.1winjs

Why button itself does not remain visible after click event which is updating label text propertly


Using blank template My default.html has following

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

    <!-- 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>

    <!-- HelloWorld references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
</head>
<body>
    <br />
    <h1 id="msg" />
    <br />
    <button id="btn">Say Hello</button>
</body>
</html>

My default.css

body { }

here is the default.html

// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    var app = WinJS.Application;

    app.onactivated = function (args) {
        WinJS.UI.processAll().done(
            function () {
                var btn = document.getElementById("btn");
                btn.addEventListener("click", btnClick);
            });
    };

    function btnClick(mouseEvent) {
        document.getElementById("msg").innerText = "Hello there";
    }
    app.start();
})();

Problem is that when I click on button, the text Hello there is displayed but button get disappears. Can someone provide any idea as what I am doing wrong that is causing button to be not shown.


Solution

  • I don't know why but changing <h1 id="msg" /> to <h1 id="msg"></h1> fixed the problem