Why does – Ace Apr 23 '20 at 05:51

  • 2
    Placing any element outside of `body` or `head` is invalid HTML, and browsers are automatically fixing the worst errors in the source code. See [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html). "_Permitted content: One `` element, followed by one `` element._" – Teemu Apr 23 '20 at 06:05
  • Awesome! I've put the script references in the tag. – Sebastiaan Apr 23 '20 at 09:40
  • 2 Answers2

    0

    It is the way webengine play with source. Most ( and almost all ) webengine put everything into body that can be ( i.e following the standard ) because body is taken as subroot for DOM structure

    Sudip Ghimire
    • 677
    • 6
    • 15
    0

    Wrapp your script inside the body tag, at the end.

    <!DOCTYPE html>
    <html>
    <head>
      <title>Etch-A-Sketch</title>
      <meta charset="UTF-8"/>
    </head>
    <body>
    
        <script type="text/javascript" src="createDOM.js"</script>
    </body>
    
    </html>