why can i not divide this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    why can i not divide this?

    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.getEle mentById("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.


  • Vjekoslav Begovic

    #2
    Re: why can i not divide this?

    It should be

    dw = parseFloat(myOb j.height) / 2;


    "Dan" <no@mail.xy> wrote in message news:bfpi0q$mmi $1@reader11.wxs .nl...[color=blue]
    > 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.getEle mentById("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.
    >
    >[/color]


    Comment

    • Evertjan.

      #3
      Re: why can i not divide this?

      Vjekoslav Begovic wrote on 24 jul 2003 in comp.lang.javas cript:[color=blue]
      > "Dan" <no@mail.xy> wrote in message
      > news:bfpi0q$mmi $1@reader11.wxs .nl...[color=green]
      >> 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.getEle mentById("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).[/color]
      > It should be
      >
      > dw = parseFloat(myOb j.height) / 2;[/color]

      or

      dw = myObj.offsetHei ght / 2

      (IE6)

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

      Comment

      • Philip Ronan

        #4
        Re: why can i not divide this?

        On 03.7.24 10:26 PM, Vjekoslav Begovic wrote:
        [color=blue]
        > It should be
        >
        > dw = parseFloat(myOb j.height) / 2;[/color]

        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@v irgin.net
        (Please remove the "z"s if replying by email)


        Comment

        Working...