#modifying css
41 messages · Page 1 of 1 (latest)
And it needs to be a string
- isn’t valid in JS variable/property names, so kebab case converts to camel case.
If it’s a class name you use quotes.
bg-main is a class name
background-color is a CSS attribute
You skipped the second half
You also appear to be missing commas, but maybe that works?
I was wrong, both formats are supported: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
You’re trying to set the style of a string
Why’d you change that? bg was fine in your old code
And?
You were
getElementsByClassName
(Use querySelector())
. for class
WTF?
That is not a class….
WTF are you trying to do? The words you’re using don’t make sense
So what’s the problem? You selected the element. Change the CSS property of that element now.
There are no CSS elements…
Again, that makes no sense…
That’s not how it works
The way you’re trying to, yes.
You add a new stylesheet or you target elements matching the class.
Apparently you can access the styles directly: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet
This is super uncommon. Good luck.
Read the link
You write proper stylesheets to begin with. Why would you need to modify a stylesheet via JS?
…
Doesn’t answer the question.
Plenty of extensions to override CSS
Modifying CSS of specific elements is common. Modifying the stylesheets themselves is just weird.
why is that a problem?
querySelectorAll('.bg-main')
you already used querySelector() above. if it's not obvious, read the docs.
you're like a walking XY problem