0

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"});
1

1 Answer 1

1

Please try this

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

instead of your code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.