I have an HTML-file and a JS-file. Here they are:
HTML:
<head>
<meta charset = "UTF-8">
<title>Quiz Maker for Moodle - EGE Exam</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script src = "script.js"></script>
<script> doc = document; </script>
</head>
JS:
var doc;
function printSomething() {
doc.writeln("HELLO");
}
You see what I'm doing here: I create a global variable to store my document there and then I use is the function. If I don't do it, and write document.writeln("HELLO")
, the function doesn't work.
However, I assume this is a bad practice. If I'm right, is there a correct way of making my document available to all functions in all JS-files I might want to attach later on?