How can I increase css values with jquery?
I want to increase values such as top and left, this is what i tried but does not work:
var left = 5;
$(.object).css("left" + 5);
the thing is that i need the value to be an integer rather than a string like "5px". I need 5 so that i can change it with numerical expressions.
From .css() documentation:
As of jQuery 1.6, .css() accepts relative values similar to .animate(). Relative values are a string starting with += or -= to increment or decrement the current value. For example, if an element's padding-left was 10px, .css( "padding-left", "+=15" ) would result in a total padding-left of 25px.
So, you can increment left with your js variable with:
var left = 5;
$(object).css('left', '+=' + left);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With