Win8: Accessing page elements in default.html outside of default.js

Posted by Arvin on Stack Overflow See other posts from Stack Overflow or by Arvin
Published on 2012-09-30T15:15:31Z Indexed on 2012/09/30 15:37 UTC
Read the original article Hit count: 383

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about windows-8