0

Why is this code not working? Is there any rule to put a script tag at the end of the body (when I put the script tag at the end of the body, the code works).

I tried putting the script tag in the head, still not working. Shouldn't the script tag work anywhere inside the body?

<html>
<head>
</head>
<body>    
<script>
    document.getElementById('output').innerHTML += ('starting...');

    var myTimer = window.setTimeout(writeEnding,500);
    document.getElementById('output').innerHTML += ('continuing...');

    function writeEnding(){
        document.getElementById('output').innerHTML += ('ending!');
    }
</script>

<p id="output"></p>
</body>
</html>
always-a-learner
  • 3,671
  • 10
  • 41
  • 81
  • this question is not new. Refer here for the answer https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup – Jalil Jun 21 '17 at 08:48
  • ... or https://stackoverflow.com/q/14028959/1169519 – Teemu Jun 21 '17 at 08:50

0 Answers0