Weird little snafu. I'm using jQuery's .css()
method to change the size of text (long story; no, I can't 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 multiple values for the CSS change.
To illustrate:
This works perfectly. It adds em
to the calculated value of victore
:
$('h1').css('font-size', victore + 'em');
This doesn't:
$('h1').css({
'font-size':victore + 'em',
'line-height':vignelli + 'em';
});
The em
needs quotes... but so does the value. Wrapping it in parens didn't work
Weird little snafu. I'm using jQuery's .css()
method to change the size of text (long story; no, I can't 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 multiple values for the CSS change.
To illustrate:
This works perfectly. It adds em
to the calculated value of victore
:
$('h1').css('font-size', victore + 'em');
This doesn't:
$('h1').css({
'font-size':victore + 'em',
'line-height':vignelli + 'em';
});
The em
needs quotes... but so does the value. Wrapping it in parens didn't work
3 Answers
Reset to default 19You shouldn't have the quotes around the whole thing:
$('h1').css({
'font-size': victore + "em",
'color':'red'
});
Here's a fiddle.
$('h1').css({
'font-size':victore + "em",
'color':'red'
});
The font-size value is required to be a string, but that string can be the result of an expression, in your case victore + 'em'
should result in the appropriate string.
$('h1').css({
'font-size': victore + 'em',
'color': 'red'
});
;
after the lastem
. – ThinkingStiff Commented Dec 11, 2011 at 5:10