Hello,
first of all, sorry for the extremly nooby quastion and my not so good English, but this makes me insane.
My HTML Code --> index.html:
<html>
<head>
<script src="main.js"></script>
</head>
<body>
<input id="btn" type="button" value="Button">
</body>
</html>
And my JavaScript Code --> main.js:
function test()
{
alert("Test");
}
btn.addEventListener ("click", test);
It is written everywhere, that the <script src="xyz"></script> should be written as high as possible, respectivly within the <head> Tags.
But the code above do not work --> Why??
The code works only if my script is written/loaded after the <input> Tag. Is this works as desinged? Should the script import really written at the end of the HTML page?
Thanks in advance.