Reputation: 559
I feel silly asking this because I should know it but I'm in a hurry and I also can't for the life of my think of the right term to put into Google to get the answer I'm looking for.
Basically using javascript/jquery I need to say "add varName's value to the existing css property of left:200px;" using the the .css in jQuery.
Upvotes: 0
Views: 823
Reputation: 69915
Go through this
//This will set or overwrite the left style property of element
//selected by elementSelector
$("elementSelector").css("left", varName);
Alternatively css
method takes a map
if you want to set multiple properties at once.
$("elementSelector").css( { left: varName });
Upvotes: 2
Reputation: 1564
var extra;
//fiddle with the value of extra
$("#myElement").css("left", 100 + extra +"px");
Upvotes: 0
Reputation: 219936
Are you trying to increment the current CSS value with the one in your variable?
If so, use this:
var varName = 20;
$('#element').css('left', '+=' + varName);
Upvotes: 2
Reputation: 3664
$('.selector').css('opacity', '0.5');
or, for multiples:
$('.selector').css({'opacity' : '0.5', 'width' : '100px'});
or, for a specific class:
$('.selector').addClass('className');
http://api.jquery.com/addClass/
Upvotes: 0