Class not applied after the change

I am trying to understand why the new class is not applied after the change. I see the new class name in my console but color of the element is not changing.

console.log(“I am inside my function”);
const element = document.getElementById(“someid”);
element.classList.remove(“class1”);
element.classList.add(“class2”);
console.log(element.className);

Output in the console shows “class2”. Am I doing something wrong?

Your code contains an unwanted character:
'lclass2"

EDIT: I see you have now corrected it in code above.

sorry this is just typo as I was changing the class names and pasting it here.

when I print

console.log(element)

I get

<span id="someid" class="class1">#</span>

I am trying to apply class2 to character # to change its color

Works here:

yes works for me as well when i take it out of the code and run it by itself

Then the issue must be somewhere else in your code.

1 Like

yeah it was all the way down on the page

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.