Win8: Accessing page elements in default.html outside of default.js
- by Arvin
I have the following page elements within default.html:
<div id ="content">
<div id="output"></div>
</div>
And within default.js:
...
args.setPromise(WinJS.UI.processAll().done(function()
{
var theOutput = document.getElementById("output");
theOutput.innerText = "This is the output";
}));
....
This successfully produces the app that just has the text "This is the output"
But if I move this into a new script script.js:
(function ()
{
"use strict";
var theOutput = document.getElementById("output");
theOutput.innerText = "This is the output";
}());
And added script.js as a script reference in default.html:
<script src="/js/script.js"></script><script src="/js/script.js"></script>
I get the error
JavaScript runtime error: Unable to set property 'innerText' of undefined or null reference
How do I access the output div in other scripts outside of default.js?