Suppose I have a page element (DIV, SPAN whatever) and want to retrieve the position and width/height of it. What is the best way?
for x/y i have this:
[code=php]
function getElementPos (el) {
var curleft = curtop = 0;
if (!el.offsetParent) {
alert(“Your browser does not support a necessary feature. Please upgrade to a newer browser”);
return;
}
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
return {left:curleft, top:curtop};
}
For width/height I am familiar with element.style.width but am wondering how reliable that is across all browsers. and whether it works if no style or class has been defined for an element.