I have been trying to add a class with classList.add but it's not working and not throwing any error.
For further actions, you may consider blocking this person and/or reporting abuse
I have been trying to add a class with classList.add but it's not working and not throwing any error.
For further actions, you may consider blocking this person and/or reporting abuse
Mike Young -
MD ARIFUL HAQUE -
Md. Razaul Haque -
Mike Young -
Top comments (3)
You have
classListName
, notclassList
.Also you are trying to do something with
buttons
, not specificbutton
in a loop.BTW. Next time try pasting code, not image of code. Ideally in a form of jsbin/jsfiddle/codepen.
Oh sorry about the presentation. This is actually my first post.
let buttons = document.querySelectorAll('button');
function display() {
buttons.forEach(buttons => {
buttons.addEventListener('click', () => {
buttons.classList.add('active')
});
})
}
Sure thing, here you have working minimal example :)
codepen.io/pavelloz/pen/YzZXzXR?ed...
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.