1

I have a problem putting variable value in quotes in Jquery:

for example:

I have a Html color code in variable color, which has a value #FFFF00. I vant to display variable value like this: "#FFFF00".

I tried something like this but it didn't work:

context.strokeStyle = "\"color\"";
Erik
  • 335
  • 2
  • 9
  • 19

3 Answers3

5

If you want to display the string wrapped in quotes then simply use:

context.strokeStyle = '"' + color + '"';
David Thomas
  • 240,457
  • 50
  • 366
  • 401
4

Just use the variable directly.

context.strokeStyle = color;

and if you want to add quotes to it:

context.strokeStyle = """ + color + """;
Kevin B
  • 94,164
  • 15
  • 164
  • 175
0

You don't need the quotes.

context.strokeStyle = color;

Should do just fine.

Adrian
  • 38,231
  • 5
  • 90
  • 87