document.getElementById newbie question

Giganews Newsgroups
Subject: document.getElementById newbie question
Posted by:  Randall (weber.ran…@gmail.com)
Date: Fri, 9 May 2008

I am a newbie trying to learn the DOM. Can someone tell me why the
first alert statement returns null, and the second returns the value
33px (which was set using the style="top:33px;" in the DIV tag).

Why doesn't the first alert statement pick up the style.left attribute
from the CSS?

<html>
<head>
<style type="text/css">
<!--
DIV.test {position:absolute; left:10px; top:10px; width:100; height:
100;}
-->
</style>
</head>
<body>
<div id="Canvas" class="test" style="top:33px;">canvas</div>
<script type="text/javascript">
var el=document.getElementById("Canvas");
alert(el.style.left);  //returns null... Why not 10px ???
alert(el.style.top);    //returns 33px
</script>

</body>

</html>

Replies