0

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?

4
  • can you post the code that translates the array into HTML? Commented Jul 30, 2012 at 13:07
  • FYI, the <font> tag and the color attribute are deprecated. Use css instead. Commented Jul 30, 2012 at 13:07
  • @jbabey - I am actualy drawing a chart and I am using the d3.js to draw the charts, my code that draws up "Dog Toys" <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> Commented Jul 30, 2012 at 13:19
  • Unfortunately, I don't have any experience with the d3.js library. I assume there is a style, or color property you can assign somehow, but I wouldn't know that. Good luck with your search. Commented Jul 30, 2012 at 13:30

2 Answers 2

3

Try

myVariable.style.color = "Red"
Sign up to request clarification or add additional context in comments.

6 Comments

Did not work, basically myVariable is a string that has a value derived from the database. I get this error"Cannot set property 'color' of undefined "
What does the string look like? From the looks of your code, you're trying to set the CSS value "color" to red on the myVariable object. This will indeed not work on a simple string.
The string returns "Dog Toys" , i need to display it in red when size is less than 0
Can you post some more code then? Like jbabey commented on your OP: Can you post the code that translates the array into HTML?
I am actualy drawing a chart and I am using the d3.js to draw the charts, my code that draws up "Dog Toys" <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>
|
1
myVariable.style.color = "red";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.