javascript - CodeCademy Codebit document.getElementById() cannot be a variable -
ok, go codebit have fun, , already, 30 seconds in, something's wrong. have div id of "main" , when window loads, start program.
html:
<link rel='stylesheet' href='style.css'/> <script src='http://code.jquery.com/jquery-1.9.1.min.js'> </script> <script src='script.js'></script> <div id="main"></div>
js:
var x = document.getelementbyid('main'); function loaded() { x.innerhtml ="willnotload!" } $(document).ready(function() {loaded();});
don't "you didn't load document, stupid?" get, because doing without variable works.
you're running selector before dom ready div you're looking doesn't exist @ time - see x
is.
to fix it, move var x = document.getelementbyid('main');
part inside loaded function.
Comments
Post a Comment