I am trying to click a button, that will then change the display of overlay on my page to none. In the console it is telling me that, startButton.addEventListener
is not a function. Can someone help me find the bug?
JavaScript
x
10
10
1
const letters = document.getElementById('qwerty');
2
const keyWords = document.getElementById('phrase');
3
const startButton = document.getElementsByClassName('btn__reset');
4
const overlay = document.getElementsByClassName('main-container');
5
var missed = 0;
6
7
startButton.addEventListener("click", function(){
8
overlay.style.display = 'none';
9
});
10
Advertisement
Answer
Get your button with getElementById, it works
JavaScript
1
5
1
let startButton = document.getElementById('button');
2
3
startButton.addEventListener("click", function(){
4
console.log('yes');
5
});
JavaScript
1
1
1
<button id="button">Go!</button>