I can run Javascript in-page, thus:
Javascript.html:
<html>
<body>
Hello <span id="mySpan"> World! </span>
</body>
<script>
function worldInSpanish() {
return "Mundo!";
}
document.getElementById('mySpan').innerHTML = worldInSpanish();
</script>
</html>
Hello Mundo!
But when I try to run it from an external file, it doesn't work.
javascript.js:
function worldInSpanish() {
return "Mundo!";
}
External_javascript.html:
<html>
<body>
Hello <span id="mySpan"> World! </span>
</body>
<script src="javascript.js">
document.getElementById('mySpan').innerHTML = worldInSpanish();
</script>
</html>
Doesn't change the text:
Hello World!
What am I doing wrong? I'm guessing that I need to do something more to "import" the function into the HTML page or "export" it from the Javascript file.
<script>element which has asrcattribute set is not executed.