0π
β
I think you should be passing the event into the function otherwise it wonβt know what event
is (where is event
being defined if itβs not being passed in as a parameter?)
activeButton(event) { // added event here
const item = event.target.parentNode.childNodes;
for (let i = 0; i <= item.length; i++) {
if (item[i].classList.contains('active')) {
item[i].classList.remove('active');
}
}
event.target.classList.toggle('active');
}
0π
Without context but I guess your loop iterate an extra time. item[length]
would return undefined
activeButton() {
const item = event.target.parentNode.childNodes;
for (let i = 0; i < item.length; i++) {
if (item[i].classList.contains('active')) {
item[i].classList.remove('active');
}
}
event.target.classList.toggle('active');
}
Source:stackexchange.com