Html Class List

how do i remove the class with javascript on html tag
9 Replies
Jochem
Jochem16mo ago
document.documentElement represents the html tag
Aldrin
AldrinOP16mo ago
this is what i have tried to list all the classes
Aldrin
AldrinOP16mo ago
but not working
Jochem
Jochem16mo ago
works for me though I'm not sure what you expect it to do, and your variable naming is a bit confusing the classList you're grabbing isn't an element, and the values in the DOMTokenList it returns aren't elements https://codepen.io/jochemm/pen/PoXZyjM?editors=1111
Aldrin
AldrinOP16mo ago
i have 2 class on html tag, i want to remove both
Aldrin
AldrinOP16mo ago
this 2 class on html tag
Aldrin
AldrinOP16mo ago
i could list it, but not able to loop and remove it
Jochem
Jochem16mo ago
this would be a lot easier to talk about if you had code to share instead of screenshots, but what's probably happening is that you're removing elements, which is shifting the index of the remaining elements, or at least something similar. If you want to remove all the elements you can do this
const htmlClassList = document.documentElement.classList;

htmlClassList.remove(...htmlClassList);
const htmlClassList = document.documentElement.classList;

htmlClassList.remove(...htmlClassList);
classList.remove takes any number of arguments, and removes each from the classlist. the ...htmlClassList takes the array-like DOMTokenList and spreads it out into individual arguments that get passed to remove
Aldrin
AldrinOP16mo ago
ok got it, thanks
Want results from more Discord servers?
Add your server