Rulian, you nailed it I think. That's working quite well for me. I was making a 'click shield' for some Javascript components to prevent obsessive users from clicking them while they're busy dealing with AJAX calls. It's basically a DIV that hovers in front of the component. At first it seemed like offsetWidth/Height failed to account for the padding/margin/borders but then I realized that I had altered the class of the DIV after displaying my click shield.
Weedpacket, I did find the need to use clientHeight for the x/y click of a mouse. Apparently the x and y params returned by a mouseclick event are not particularly useful for positioning contextmenus or other object. Thanks to the wonderful quirksmode for the inspiration behind this bit of code.
/**
* Returns the mouse position from an event
* @param Event e The mouse-related event
* @return Object An object with x and y properties
*/
function getPos(evt) {
var posx = 0;
var posy = 0;
if (evt.pageX || evt.pageY) {
posx = evt.pageX;
posy = evt.pageY;
}
else if (evt.clientX || evt.clientY) {
posx = evt.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = evt.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
return {x:posx, y:posy};
}
Nog, you are right about the weirdness of layout being a severe complication in this mess. I have started to use only STRICT doctypes which helps (but NOT if you've designed your entire page for TRANSITIONAL - DO NOT SWITCH). I also seem to have learned that any htmlElement.style.propertyName only contains a value if 'propertyName' has been explicitly applied by giving the element itself using a style attribute. You can't retrieve any style properties inherited from a class or parent or anything.