JQuery.css () function with variables and multiple values

Strange little snafu. I am using jQuery .css() method to resize text (long story, no, I can not use media queries) using a variable and I need to add em to it. I'm not sure what the syntax is, because there are several meanings for modifying CSS.

To illustrate:

It works great. It adds em to the computed victore value:

 $('h1').css('font-size', victore + 'em'); 

It does not mean:

 $('h1').css({ 'font-size':victore + 'em', 'line-height':vignelli + 'em'; }); 

em needs quotes ... but so does the value. Wrapping it in parens did not work

+8
javascript jquery syntax css
source share
3 answers

You should not have quotes around everything:

 $('h1').css({ 'font-size': victore + "em", 'color':'red' }); 
+17
source share

The font size value must be a string, but this string can be the result of an expression, in your case victore + 'em' , the corresponding string should appear.

 $('h1').css({ 'font-size': victore + 'em', 'color': 'red' }); 
0
source share

Here's the fiddle .

 $('h1').css({ 'font-size':victore + "em", 'color':'red' }); 
0
source share

All Articles