0

Why can't I do this? Or how can i do this?

/* this does not work and I want to achieve something like this */
el.style.setProperty("--member-clr", var('--server-clr'));

/* only below works */
el.style.setProperty("--member-clr", 'black')

CSS:

main {
   --server-clr: linear-gradient(blah,blah)
}

I tried above and simply what I need to work does not work(it's illegal I get it so what is my best option?)

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
  • Typo: Quotes go around the *whole* value: `el.style.setProperty("--member-clr", 'var(--server-clr)')` – Quentin Feb 13 '23 at 15:07
  • When you tried to set the CSS value `black`- did you then use `black` in your code, or did you use `'black'`? The latter, and for a good reason, because you meant that as _text_, and not as reference to a JavaScript variable named `black`. And `var('--server-clr')` is _not_ a JavaScript function either ... – CBroe Feb 13 '23 at 15:08
  • @Quentin btw, how can I make this work? cover.style.setProperty("--cover-clr", "var(o.Background)"); I tried both "var(${o.Background})" or `"var(${o.Background})"` – anonymous internet Feb 13 '23 at 15:35
  • @anonymousinternet — You now seem to have an entirely different question about [string interpolation in JavaScript](https://stackoverflow.com/questions/1408289/how-can-i-do-string-interpolation-in-javascript). – Quentin Feb 13 '23 at 15:36
  • sorry @Quentin you are right..sorry about that and I just figured it out. thank you! – anonymous internet Feb 13 '23 at 15:39

0 Answers0