HighDots Forums  

why can i not divide this?

Javascript JavaScript language (comp.lang.javascript)


Discuss why can i not divide this? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dan
 
Posts: n/a

Default why can i not divide this? - 07-24-2003 , 05:05 PM






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.



Reply With Quote
  #2  
Old   
Vjekoslav Begovic
 
Posts: n/a

Default Re: why can i not divide this? - 07-24-2003 , 05:26 PM






It should be

dw = parseFloat(myObj.height) / 2;


"Dan" <no (AT) mail (DOT) xy> wrote

Quote:
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.





Reply With Quote
  #3  
Old   
Evertjan.
 
Posts: n/a

Default Re: why can i not divide this? - 07-24-2003 , 05:45 PM



Vjekoslav Begovic wrote on 24 jul 2003 in comp.lang.javascript:
Quote:
"Dan" <no (AT) mail (DOT) xy> wrote in message
news:bfpi0q$mmi$1 (AT) reader11 (DOT) wxs.nl...
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).
It should be

dw = parseFloat(myObj.height) / 2;
or

dw = myObj.offsetHeight / 2

(IE6)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #4  
Old   
Philip Ronan
 
Posts: n/a

Default Re: why can i not divide this? - 07-24-2003 , 05:56 PM



On 03.7.24 10:26 PM, Vjekoslav Begovic wrote:

Quote:
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")

--
Philip Ronan
phil.ronanzzz (AT) virgin (DOT) net
(Please remove the "z"s if replying by email)




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.