Answer the question
In order to leave comments, you need to log in
What to do if CORS error?
In general, there is such code:
HTML:
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Test</title>
<link href="style.css" rel='stylesheet' type='text/css'>
<script type='module' src='app.js'></script>
</head>
<body>
<h1 id='money'>0</h1>
<button type='button' id='farm'>Click me!</button>
</body>
</html>
#money {
color:crimson;
text-align: center;
}
#farm {
color:darkblue;
background-color:firebrick;
width: 100%;
height: 50px;
font-size: 25px;
}
body {
background-color: gray;
}
let money = document.getElementById('money')
const farm = document.getElementById('farm')
function addMoney() {
money.textContent++
}
farm.addEventListener('click', addMoney)
Answer the question
In order to leave comments, you need to log in
Well, first of all, remove type=module, you don't need it.
And secondly, include the script not in the head, but before the closing tag </body>
.
You must be making a mistake here
Cannot read property addEventListener from undefinded
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question