Marky68
Marky68

Reputation: 95

How do I get the position of a relative element?

I have a div that has a relative position but I need to get the actual absolute position in that moment. Is that possible?

Upvotes: 0

Views: 31

Answers (2)

VisioN
VisioN

Reputation: 145458

For JQuery you can use offset:

var pos = $(element).offset();
console.log("Left: " + pos.left);
console.log("Top: " + pos.top);

DEMO: http://jsfiddle.net/NVVFM/

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337714

Use offset().

var top = $("#myElement").offset().top;
var left = $("#myElement").offset().left;

Example fiddle

Upvotes: 1

Related Questions