I'm trying to brush up my javascript and have a simple setup of html, CSS and JS connected.
The console.log prints out Clicked so I know it's working, but my code is wrong and I can't see it. The element is not checking for the existing class 'red'.
I'd like to check if the class red is there, and if it is then remove it and if its not, then add the class.
Can any of you point me in a direction?
TIA
tekst.addEventListener("click", () => {
console.log("Clicked");
tekst.classList.add("red");
if (tekst.classList.contains("")) {
tekst.classList.add("red");
} else if (tekst.classList.contains("red")) {
tekst.classList.remove("red");
}
});