scott100
05-29-2006, 11:18 PM
Hi, i am trying to find the width of characters in an element like so but it's coming up blank
<head>
<script>
function check(){
var val=document.getElementById('mydiv').style.width;
alert(val);
}
</script>
</head>
<body onload="check()">
<div id="mydiv">I am a div</div>
</body>
I know that if i add style="width:100%" to the div then the function would return 100% but say i wanted to find how much width the above paragraph actually took up (ie looks about 40px), is this possible :confused:
<head>
<script>
function check(){
var val=document.getElementById('mydiv').style.width;
alert(val);
}
</script>
</head>
<body onload="check()">
<div id="mydiv">I am a div</div>
</body>
I know that if i add style="width:100%" to the div then the function would return 100% but say i wanted to find how much width the above paragraph actually took up (ie looks about 40px), is this possible :confused: