Ashish Kasma
Ashish Kasma

Reputation: 3642

Is this possible to get div element position in JQuery

Is this possible to get div element position in JQuery?

homebox is hidden and having right as 0px , I want to animate homebox to container.

so i tried this code

   $("#homebox").animate({ left:$("container").position().left}, 500);

Upvotes: 0

Views: 97

Answers (2)

codef0rmer
codef0rmer

Reputation: 10520

You can use either Offset or Position

Offset - Get the current coordinates of the first element in the set of matched elements, relative to the document.

Position - Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.

Upvotes: 1

sQVe
sQVe

Reputation: 2015

I think it's .offset() your looking for.

$("#homebox").animate({ left: $("#container").offset().left }, 500);

The above should hopefully work.

Also, should not the container have an ID? # is missing from your selector.

Upvotes: 4

Related Questions