I have <button id="submit" onclick="myFunction()">Submit</button> in my html file and
document.addEventListener("click", myFunction);
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
in my JS file, but I am recieving this error:
ReferenceError: myFunction is not defined
How can I fix it?
As per CherryDT, you can remove the onclick="myFunction()" from the button and do it this way
document.getElementById("submit").addEventListener("click", myFunction);
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}