Linked Questions

Popular Questions

Apply CSS style within .js var

Asked by At

I'm currently building a game which relies on a random number to show a particular string from an array within a .js file. What I want to do is effectively apply a span element to certain text within the array - eg. make positive outcomes green & negative red, however I can't figure out how to do this outside of html. Eg:

var data = [
  {"label": "Question 1", "value": 1, "question": "Awareness: High, Consistency: Low."},
  {"label": "Question 2", "value": 1, "question": "Consistency: High, Awareness: Low."},
]

A separate set of code, after selecting a random number, returns data[i].label. How would I set a span within js so that the "High" strings return in green, and "Low" return in red?

Cheers.

Related Questions