The following code is producing an error for me
tab.addEventListener("click", (e) => {
e.preventDefault();
if (document.getElementsByTagName("a").classList.contains("active")) {
document.getElementsByTagName("a").classList.remove("active");
} else {
console.log("nothing")
}
})
It is producing this error in the console.
Uncaught TypeError: Cannot read properties of undefined (reading 'contains')
I am confused, because I am not sure why this error is happening. Even stranger, when the classList.remove("active")
is outside of the conditional, the same error occurs, with contains
replaced with add
. Can someone explain to me why this error is happening?
Thank you