Is it possible to apply a CSS class to the <body> tag of an HTML document?
I have so far been attempting something as such:
document.getElementsByClassName("body").add("cssClass");
The hope is to apply a filter over the entire DOM as to darken the page at specific times, but keep all functionality of the DOM itself.
Or, shorter: document.body.className = 'classname';
As suggested by Gaby, to avoid replacing of already applied class(es):
document.body.classList.add('classname')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With