PDA

View Full Version : how to retrieve html element position?


danab
01-06-2003, 02:34 PM
How does one get the information about the postion of an HTML element?
I tried testing a simple html page that would alert me of the position of a <button> element in the page.
It did not work.
This was the code:
-----------------------
<html>
<body onload="test()">
<button id=obj name=obj>OBJ</button>

</body>



<script language=javascript>
function test()
{
alert(document.all.obj.width);

}
</script>
</html>
-----------------------

I just get 'Undefined' in my alert window.
Why did it not work?
Thanks.
Danny Abraham.

beetle
01-06-2003, 03:03 PM
You can use offsetWidth (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/offsetwidth.asp) or clientWidth (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/clientwidth.asp). They each act differently, and the clientWidth page I just linked you to has a good example of the difference.

They are both IE only, but since you are using document.all, which is also IE only, that shouldn't be a problem :D

danab
01-07-2003, 11:40 AM
Thanks...