Geez, I cant figure this out!!!

liunx

Guest
<html><br />
<head><br />
<style type="text/css"><br />
.myLyrSty{position:absolute;height:100px;width:100px;top:20px;left:20px;background-color:red;}<br />
</style><br />
</head><br />
<body><br />
<div id="myLyr" class="myLyrSty"></div><br />
<script language="javascript"><br />
alert(document.all.myLyr.style.top)<br />
</script><br />
</body><br />
</html><br />
<br />
<br />
This alert box will be EMPTY because theres no value. Why is there no value? The layer is positioned to the top and left property assigned to it by the class but there is no value. Anyone know why?<!--content-->No one knows why I cant get the values for a layer that was created froma class?<!--content-->what values are you expecting?<!--content-->The style object is not a window into an elements current style, rather it reflects the values of the style attribute of the element.<br />
<br />
Due to the Cascading nature of stylesheets, and the Container model of HTML, it is difficult to tell exactly what the current properties of an element are. Elements can draw their properties from HTML attributes, in-line styles, stylesheets or HTML definitions.<br />
For this reason Microsoft introduced the currentStyle property (<!-- m --><a class="postlink" href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/currentstyle.asp">http://msdn.microsoft.com/workshop/auth ... tstyle.asp</a><!-- m -->) in IE5. <br />
<br />
If you change alert(document.all.myLyr.style.top) to be alert(document.all.myLyr.currentStyle.top) using IE5+ you'll get a result.<!--content-->
 
Back
Top