shabeer90
shabeer90

Reputation: 5151

Setting color to a string using javascript

I am building a dynamic array and have the following code, i am trying to add a color to the "name" of the array. Everything else works perfectly apart from "fontcolor("red")" .

if (val < 0) {
    myArray.push({
            "name" : myVariable.fontcolor("red"),
            "size" : -10
    });
} else {
    myArray.push({
            "name" : myVariable,
            "size" : 5
    });
}

I end up with the following when displayed on thet HTML page:

<font color="red">Strong rubber(minus)</font> 

I am actualy drawing a chart and I am using the d3.js to draw the charts, my code that draws up "Dog Toys". myVariable has the value "myVariable"

 <g style="cursor: pointer; opacity: 1; " transform="translate(0,0)"> 
  <text x="-6" y="10" dy=".50em" text-anchor="end">Dog Toys</text> 
  <rect width="478.57142857142867" height="20" style="fill: #4682b4; "></rect> 
 </g> 

Any idea how i could set a color to text, when its displayed on the web page?

Upvotes: 0

Views: 2325

Answers (2)

voodoo417
voodoo417

Reputation: 12101

myVariable.style.color = "red";

Upvotes: 1

Matthias
Matthias

Reputation: 13414

Try

myVariable.style.color = "Red"

Upvotes: 3

Related Questions