jQuery: Move element by relative value

Fuxi picture Fuxi · Nov 27, 2009 · Viewed 23.2k times · Source

(Meaning an elements left-value): What's the easiest way to move an element - e.g. 10px to the left (from its current position)?

Answer

devongovett picture devongovett · Nov 27, 2009

Here is a quick example using jQuery:

$("#el").css({
    left: $("#el").position().left - 10 + "px"
});

Note: the element that you want to move must either be positioned absolutely or relatively.