I started learning JS recently, and I have a problem I can not figure out… I tried a lot of solutions and nothing helped.
I have a very basic JS code:
<body>
<h1>My First JS Page</h1>
<p id="demo">My First Paragraph.</p>
<script>
document.getElementById("demo").innerHTML="My First JavaScript";
</script>
</body>
The code works when the script is below but if I attach the same script as an external, and connects it to the HTML in the HEADER, the script just does not work ….
You should wrap external scripts in a
example
HTML
JS Filename test.js