Assign Variable to Style Property

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

    Assign Variable to Style Property

    Hi,

    I am desperately trying to assign a variable or rather the return value of a
    function to a style property.

    document.getEle mentById("line" ).style.width=g etInsideWindowW idth();

    But it is not working.. and I have no idea why. I can output the return
    value of getInsideWindow Width with alert(getInside WindowWidth();) and its
    working fine..

    Thanks for any help!

    Regards,
    Axel
  • Martin Honnen

    #2
    Re: Assign Variable to Style Property



    Axel Siebenwirth wrote:

    [color=blue]
    > I am desperately trying to assign a variable or rather the return value
    > of a function to a style property.
    >
    > document.getEle mentById("line" ).style.width=g etInsideWindowW idth();[/color]

    For a start make sure you set a proper CSS width value e.g.
    ...style.width = getInsideWindow Width() + 'px';
    If that doesn't help then provide some more details on what the function
    returns, what kind of element line is, which browser that fails with.

    --

    Martin Honnen

    Comment

    • Axel Siebenwirth

      #3
      Re: Assign Variable to Style Property

      Martin Honnen wrote:[color=blue]
      >
      >
      > Axel Siebenwirth wrote:
      >
      >[color=green]
      >> I am desperately trying to assign a variable or rather the return
      >> value of a function to a style property.
      >>
      >> document.getEle mentById("line" ).style.width=g etInsideWindowW idth();[/color]
      >
      >
      > For a start make sure you set a proper CSS width value e.g.
      > ...style.width = getInsideWindow Width() + 'px';[/color]

      That did it. Thanks!

      I did ...style.width = getInsideWindow Width() + "px";
      and that didn't work...

      Axel

      Comment

      • rw

        #4
        Re: Assign Variable to Style Property

        I think element must be block type - display:block
        rw

        Axel Siebenwirth wrote:[color=blue]
        > Hi,
        >
        > I am desperately trying to assign a variable or rather the return value
        > of a function to a style property.
        >
        > document.getEle mentById("line" ).style.width=g etInsideWindowW idth();
        >
        > But it is not working.. and I have no idea why. I can output the return
        > value of getInsideWindow Width with alert(getInside WindowWidth();) and
        > its working fine..
        >
        > Thanks for any help!
        >
        > Regards,
        > Axel[/color]

        Comment

        Working...