I have been trying to run a simple HTML document with an external JS file with a function that when you press on a button in the HTML document the content of the HTML (the h1) changes to "paragraph changed". But when I call the JS function in the HTML document it says it doesn't exist. I tried out the code in different online console include VSCODE and it works but for some odd reason this console is failing to make a simple call to my JS function in an external file.
Here is my code in the HTML Document (cut it):
...
<body>
<h1 id="header">Hello World</h1>
<button type="button" onclick="myFunction()">Click Me</button>
<script src="src/script.js"></script>
</body>
...
In my JS document in src/script.js:
function myFunction() {
document.getElementById('header').innerHTML = 'Paragraph changed.';
}
Error message:
ReferenceError: myFunction is not defined
Am I doing something wrong or is the console the problem?