Forum Moderators: open
<html >
<body onload="javascript:doit()">
<script language=javascript>
function doit()
{
var d=document.getElementById('im').style.left
alert(d)
}
</script>
<img src=image.gif id=im name=im>
</body>
</html>
Here is a little function that will return the current/computed style of elements. Just pass an object reference and a string containing a style attribute and the function will pop an alert box with the value. This will display the default value of non-styled elements as well as the style applied by internal/external stylesheets.
//this function will get the current/computed style in IE and Moz/FF
function getStyle(obj,cAttribute){
//if IE
if (obj.currentStyle){
var curVal=eval('obj.currentStyle.'+cAttribute)
}else{
//if Mozilla/FF
var curVal=eval('document.defaultView.getComputedStyle(obj, null).'+cAttribute)
}
alert('style attribute '+cAttribute+' = ' + curVal)
}
ajkimoto