Skip to content
Advertisement

Add Event Listener not Connecting to Button

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?

const letters = document.getElementById('qwerty');
const keyWords = document.getElementById('phrase');
const startButton = document.getElementsByClassName('btn__reset');
const overlay = document.getElementsByClassName('main-container');
var missed = 0;

startButton.addEventListener("click", function(){
overlay.style.display = 'none';
});

Advertisement

Answer

Get your button with getElementById, it works

let startButton = document.getElementById('button');

startButton.addEventListener("click", function(){
  console.log('yes');
});
<button id="button">Go!</button>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement