DEV Community

Discussion on: Why are these codes not working?

pavelloz profile image
Paweł Kowalski • Edited on

You have classListName, not classList.
Also you are trying to do something with buttons, not specific button in a loop.

BTW. Next time try pasting code, not image of code. Ideally in a form of jsbin/jsfiddle/codepen.

adedams profile image
Adedams Author

Oh sorry about the presentation. This is actually my first post.

let buttons = document.querySelectorAll('button');

function display() {
buttons.forEach(buttons => {
buttons.addEventListener('click', () => {

pavelloz profile image
Paweł Kowalski

Sure thing, here you have working minimal example :)

I dont think you need display function at all, but since you do, you need to execute it, so evrything inside (including attaching event listeners) occur.