I'm trying to change the classes of multiple siblings upon a click event, some of them might have multiple classes to each, but the class that I intend to change is always the first one, so that is what I came with
let classList = event.currentTarget.classList;
if (classList[0] === 'open'){
classList[0] = 'close';
event.currentTarget.classList = classList;
return;
}
let sibllingList = event.currentTarget.parentElement.children;
for (let i=0;i<sibllingList.length;i++) {
classList = sibllingList[i].classList;
if (classList[0] === 'open') {
classList[0] = 'close';
sibllingList[i].classList = classList;
break;
}
}
classList = event.currentTarget.classList;
if (classList[0] === 'close'){
classList[0] = 'open';
event.currentTarget.classList = classList;
}
This worked when I was working with a single class and using className instead of classList, and the function worked fine, but when I switched it to classList, it didn't work and threw the following error
Uncaught TypeError: Failed to set an indexed property on 'DOMTokenList': Index property setter is not supported.