joerg pfeffer wrote:
hello,
I want to read the style.top of an image when I open the page with:
document.getElementById("myimage").style.top
But unfortunately the value has no properties....
Does this happen, since the image isn't loaded already?
As Stephanie pointed out, an element's style object will not have values
for properties inherited from CSS rules or general layout.
You need to investigate getComputedStyle and getCurrentStyle, try the
following function but beware that Mozilla et al want standard
hyphenated style names and IE wants them camelCase. In if you only want
'top', then it won't be a problem:
function GetCurrentStyle( el, prop ) {
if ( window.getComputedStyle ) {
// Mozilla et al
return window.getComputedStyle(el, '').getPropertyValue(prop) );
} // IE5+
else if ( el.currentStyle ) {
return el.currentStyle[prop];
} // IE4
else if ( el.style ) {
return el.style[prop];
}
}
There is a thread "RegExp for hyphen to camelCase" that discusses
solutions to the camelCase/hyphen issue:
<URL:http://groups-beta.google.com/group/comp.lang.javascript/browse_frm/thread/6c90313661245bb5/72776c776ce21e48?q=camelcase&rnum=1&hl=en#72776c77 6ce21e48>
--
Rob