Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript ClassList in JS not working.. Reply To: ClassList in JS not working..

#250605
Shikkediel
Participant

Or you could pass it as a parameter of course…

var test = document.getElementById("icon");

test.addEventListener("click", function() {
    var text = document.getElementById("text");
    loadClass(text);
});

function loadClass(txt) {
    if (txt.classList.contains("newClass")) txt.classList.remove("newClass");
    else txt.classList.add("newClass");
}

Or is that called an argument… I never know. :-/