Jon Snow's papa Jon Snow's papa - 9 months ago 49
jQuery Question

Add to current CSS top value

I have this jQuery:


But it is not working. I have tried this way too:


But it also did not work.


You have to grab the current top value, and then add a new value, and then append the "px" back on when you set the value using .css()

Here is what it would look like:

var element = $(".ta").siblings(".Aname:eq(0)");
var currTop = Number(element.css("top").replace("px", ""));
var amountToAdd = $(".Text").height() + 15;
$(element).css("top", (currTop + amountToAdd + "px"));

And here is a WORKING DEMO