Jon Snow's papa Jon Snow's papa - 1 year ago 71
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download