views:

64

answers:

1

This is pretty rudimentary, but I want to know how I can access a property like height as a string. The mouseover alert here simply returns "undefined" (and saying height.value in the alert doesn't help either):

<html>
 <body>
  <div id="wut" align="center" height="10" onmouseover="alertheight()">
    hi.
  </div>
  <script type="text/javascript">
    function alertheight() {
        alert(document.getElementById("wut").height);
    }
  </script>
 </body>
</html>
+5  A: 

This is because most HTML elements do not have a height property (and those that have may not necesarely indicate the height in pixel). So the height attribute you added to the div-tag is ignored by the browser. Use css styles to define the heights of div's and other elements:

<div id="wut" align="center" style="height: 10px" onmouseover="alertheight()">

What I guess you are looking for however is likely clientHeight and similar properties: https://developer.mozilla.org/en/DOM/element.clientHeight

inflagranti
That is indeed what I was looking for, thanks.
Rujiel
@Rujiel: If this is what you were looking for, please mark this answer as the answer. (Click the check-mark, just under the voting buttons.)
Brock Adams