why can i not divide this?

D

Dan

Hi,

I want to get the height of an element and dividing by 2, but i don't know
how.
See the code:
<DIV ID="myDiv" STYLE="position:absolute; height:200">
....</div>

<script>
myObj = document.getElementById("myDiv").style;
dw = myObj.height / 2;
alert(dw)
</script>

Without dividing, i get '200px'.
With dividing, it produces "NaN".
I also tried dw=parseFloat( myObj.height / 2).

Thanks for help.
Dan.
 
P

Philip Ronan

It should be

dw = parseFloat(myObj.height) / 2;

It should also be STYLE="position:absolute; height:200px"

The height attribute is a string, not a number. That's why you get "NaN"
when you divide it by 2 ("NaN" = "Not a Number")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top