0

According to jQuery documentation: the difference between position and offset is the following:

The .position() method allows us to retrieve the current position of an element relative to the offset parent. Contrast this with .offset(), which retrieves the current position relative to the document. When positioning a new element near another one and within the same containing DOM element, .position() is the more useful.

How can I set a new position to a selector? All examples refer to setting offsets (or top/left) which is not what I need.

Community
  • 1
  • 1
yazanpro
  • 4,512
  • 6
  • 44
  • 66
  • jQuery's `position()` is a getter only, and as you've read in the documentation it gets the current coordinates of the first element in the set of matched elements, relative to the offset parent. Sounds complicated, but that's really what CSS `top` and `left` do as well, they set the position relative to the parent, as long as the element is positioned relative or absolute – adeneo May 23 '15 at 06:38
  • @adeneo In my code, when I accessed `.css` for `top` and `left`, I got zeros (unlike the `position()` method which returned real values), the fact that led me to believe that they are two different things. – yazanpro May 23 '15 at 06:40
  • That's because `position` returns real values, while `left` and `top` returns whatever the styles are set to, and does not account for margin, padding, borders etc. There's no way to set a position other than using regular CSS styles like `top` and `left` – adeneo May 23 '15 at 06:48

0 Answers0