lkssmnt
lkssmnt

Reputation: 45

adding an amount of pixels saved in a variable to a css property in jQuery

I want to add an amount of pixels, that is stored in my variable "x" to a css property in jQuery.

I know that since jQuery 1.6 you can easily use something like this:

$(this).css({top: "+=150"});

But when I use a variable instead of the 150 it doesn't work, since variables have to be written out of quotation marks.

$(this).css({top: "+= x"});

Upvotes: 0

Views: 134

Answers (1)

Ferhat BAŞ
Ferhat BAŞ

Reputation: 797

Please try this

$(this).css({top: "+= "+ x +"px"}); 

instead of your code

Upvotes: 1

Related Questions