some problem of getting the position of an object

M

Mr. x

Hello,
I have simple table
<table id = "mytable" ....>
....
</table>

I want to get the left position of the table.

Everything I did getting wrong :

mytable.left doesn't work, neither mytable.style.left,
mytable.getAttribute("left") ...

What is the correct syntax for getting the position of the table element
(and others ...) ?

Thanks :)
 
L

Lasse Reichstein Nielsen

Mr. x said:
<table id = "mytable" ....>
...
</table>

I want to get the left position of the table.

For what?
Everything I did getting wrong :

mytable.left doesn't work, neither mytable.style.left,

I hope mytable was declared by, e.g.,
var mytable = document.getElementById("mytable");
You should not expect to be able to use the name/id of an element
as a global variable, just because some browsers allow it.
mytable.getAttribute("left") ...

You haven't set the attributes style="left:..." or left="...", so
neither style.left nor getAttribute("left") should work.
What is the correct syntax for getting the position of the table element
(and others ...) ?

There is no official standard for this.

Many browsers allow you to write:
mytable.offsetLeft
That gives the box that this element is positioned relative to. Often,
that element is the document itself. If not, you can find the element
as mytable.offsetParent.

Some allow you to find the current CSS affecting the element:
IE:
mytable.currentStyle.left
Mozilla/Opera 7.2:
document.defaultView.getComputedStyle(mytable,"").left
However, the result of this is just "auto" if the element isn't
positioned.

Good luck.
/L
 
V

VK

unless you explicitly positioned an object on the page (absolutely or
relatively), it's position is "null" meaning "wherever the HTML Parser
(disposed by now so not available) placed me during the page rendering".
 
M

Mr. x

The problem is that,
when I have found a javascript scroller (marquee - a scroller of multiple
lines), and I want to change it a little bit, so it fits the coordinates of
my object (that's why I need some way to get the left, top ... of my
object),
and not at a fixed position, so I need to know what is the top, left, right
& bottom of my object.
I would like a javascript scroller maker, or a script for scrolling lines,
that enable some quick changes that it will fit my objects positions,
please.

Thanks :)
 

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
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top