JavaScript Characters: Quotation Marks

By: Dusty Arlia
Published on Wednesday, October 23, 2013, 08:06 AM
Last Updated on Saturday, July 11, 2015 at 7:49 PM
Total Updates: 3

When you style something with CSS, you would do it like this:

border: 1px solid red; font-size: 12px; font-family: Arial;

You will notice that there are no quotation marks. But if you would like to do the same styling with JavaScript, you will have to put the property values in quotation marks, because these are strings. Here is how you would apply the same CSS rules using JavaScript: = "1px solid red"; = "12px"; = "Arial";

If you are computing your property value, make sure you concatenate your unit of measurement in quotation marks. Concatenating your unit of measurement in quotation marks changes your numeric result into a string as a side effect. Here is an example:

//computed example = (l_border + l_padding + body + r_padding + r_border) + " px";

//taking a numeric variable example = my_font_size + "px";

All the properties of the CSSStyleDeclaration object hold the values to your css properties. These values are strings and need to be placed in quotation marks: = "red"; = "12px";'Arial';