div - position - offsetParent

V

Vittore Zen

Hi,

a little question.

I have some nested tables with some divs (so default set is relative - ok?)

Now, i need to draw a line from one div to another. The problem is to
find the position of div

I use these functions:

function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}



But these give an error on offsetParent. The browser (IE 6) says that is
null (or it isn't a object).

Any idea?

Thanks
v.
 
M

Martin Honnen

Vittore said:
I have some nested tables with some divs (so default set is relative - ok?)

What is "default set"?
Now, i need to draw a line from one div to another. The problem is to
find the position of div

I use these functions:

function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}

I would rather use
if (typeof obj.offsetLeft != 'undefined') {
do {
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
while (obj)
}
But these give an error on offsetParent. The browser (IE 6) says that is
null (or it isn't a object).

For which line? And what do you pass in as obj when you call the function?
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top