#modifying css

41 messages · Page 1 of 1 (latest)

subtle pier
#

backgroundColor

#

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

subtle pier
#

rgb() is a CSS function not a JS function.

#

#

You put quotes around it

subtle pier
#

You also appear to be missing commas, but maybe that works?

subtle pier
#

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

subtle pier
#

WTF?

subtle pier
#

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.

#

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.

subtle pier
#

you're like a walking XY problem