JavaScript innerHTML not updating element

The element doesn’t exist at the time you’re attempting to set a value. You need to call this after the <h1> has been added to the DOM.

You can either move this <script> tag down further, or add your logic to a function which ought to be called when the document has been loaded:

window.onload = function() {
    /* Add your logic here */
}

Demo: http://jsfiddle.net/Lr2Hm/

Leave a Comment