Absolute position?

S

Samuel

Hi,

Is it possible to get absolute position of element with javascript?
e.g. I have textbox somewhere in table. Textbox relative to table cell
position is 0,0. How can I get Textbox absolute position on page??
Please, any ideas, I'm going crazy...

thanks
 
S

Samuel

AAARRRGGHHHH!!!

It dosen't work if textbox is in table, txtQuery.offsetTop returns only
relative to table cell....
 
M

Martin Honnen

Samuel said:
It dosen't work if textbox is in table, txtQuery.offsetTop returns only
relative to table cell....

Walk the offsetParent axis and add offsetTop and offsetLeft e.g.

function getPageCoords (element) {
var coords = { x: 0, y: 0 };
while (element) {
coords.x += element.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
return coords;
}

var coords = getPageCoords(someElement);
// use coords.x and coords.y here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top