title: can someone explain to me why i get an Uncaught TypeError: cannot set property of null
body: <pre><code>(function() {
          var myFunc = {
               init : function() {
                  alert("I need");
                  document.getElementById("myDiv").innerHTML = "help";
              }
          };
  window.myFunc = myFunc;
  })();
  myFunc.init();
  </code></pre>
  
  <p>The alert() message works but the Uncaught TypeError is thrown when it reaches the next line. Can anyone explain to me why and how to fix it? I assume it is something to do with the scoping of the function as it will work if nested within the myDiv rather than the linked .js file.</p>
  
  <p>Thanks</p>