JavaScript jQuery .css() function with variables and multiple values jquery function multiple variable,jquery function multiple parameter

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

Answer:1

You shouldn't have the quotes around the whole thing:

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

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' 
});
Answer:3

I'm following a tutorial on importing and displaying images on an HTML5 canvas. Everything works fine, until I try to change the image itself. For example, I'll have a yellow circle as my image, and ...

I'm following a tutorial on importing and displaying images on an HTML5 canvas. Everything works fine, until I try to change the image itself. For example, I'll have a yellow circle as my image, and ...

This is an odd problem. I have a client object that I am building up using Crockford-esque public/private members: var client = function() { var that, remote_data, other_data; // add public ...

This is an odd problem. I have a client object that I am building up using Crockford-esque public/private members: var client = function() { var that, remote_data, other_data; // add public ...

  1. wait return function javascript
  2. wait return function javascript callback

In a very simple jQuery modal, I close the modal by clicking on CLOSE as $('#close').click(function(e) { e.preventDefault(); $('#overlay, #alertModalOuter').fadeOut(400, function() { $(this)....

In a very simple jQuery modal, I close the modal by clicking on CLOSE as $('#close').click(function(e) { e.preventDefault(); $('#overlay, #alertModalOuter').fadeOut(400, function() { $(this)....

  1. close modal on click outside modal
  2. close modal click outside bootstrap
  3. close modal click outside react
  4. close modal click outside jquery
  5. close modal click outside angular 2
  6. close modal click outside js
  7. close modal on click outside
  8. close modal when click outside

I'm using Cleditor http://premiumsoftware.net/cleditor/docs/GettingStarted.html. I want to get the value on keyup and insert the text into another div. cleditor comes with change() event that i'm ...

I'm using Cleditor http://premiumsoftware.net/cleditor/docs/GettingStarted.html. I want to get the value on keyup and insert the text into another div. cleditor comes with change() event that i'm ...