JSFiddle - React, Tailwind, and code Playground
by pomeh
HTML
<div id="timer"></div>
JavaScript
// test case for http://stackoverflow.com/questions/10601842/document-write-and-innerhtml-in-function-call
// to test this script, try changing the parameters value on the left
// try "no wrap (body)", "no wrap (head)" and "onLoad"
// with "no wrap (body)", the script tag is positioned at the end of the HTML page (before </body>), so the div#timer exists and can be used
// with "no wrap (head)", the script tag is positioned in the head tag, so the div#timer does not exists and can not be used ! This is the problem you're facing
// with "onLoad", the script will executed onyl when the page has fully loaded, so the script tag position doesn't matter, when the script will be executed, the div#timer will exist
// try changing the settings and see the differents results
// actual setting is "no wrap (body)", the console should display the element
console.log( document.getElementById("timer") );