Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. div style.height

div style.height

Scheduled Pinned Locked Moved Web Development
helpjavascripttoolsquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CoolASL
    wrote on last edited by
    #1

    Hi all, I am getting this quite an unusual error in my JavaScript script. What i am trying to do is to increase the height of a DIV named as f4 as follows:

    var z = f4.style.height + 22;
    f4.style.height = z;
    

    As soon as the second line is executed, i get an error in the browser which says "Invalid Argument" and the height remains unchanged. Initially i thought that this was happening because i did not mention any height attribute. But it is occuring even after providing the same. I am really confused. Any help will be highly appreciated. Thanks in advance. *** Who said nothing is impossible? I have been doing it for a long time *** -- modified at 13:21 Monday 10th April, 2006

    G 1 Reply Last reply
    0
    • C CoolASL

      Hi all, I am getting this quite an unusual error in my JavaScript script. What i am trying to do is to increase the height of a DIV named as f4 as follows:

      var z = f4.style.height + 22;
      f4.style.height = z;
      

      As soon as the second line is executed, i get an error in the browser which says "Invalid Argument" and the height remains unchanged. Initially i thought that this was happening because i did not mention any height attribute. But it is occuring even after providing the same. I am really confused. Any help will be highly appreciated. Thanks in advance. *** Who said nothing is impossible? I have been doing it for a long time *** -- modified at 13:21 Monday 10th April, 2006

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      The height attribute is a string value, that may contain something like "100px". If you add the value 22 to the string, the value will be converted to a string, and the result will be "100px22". This is of course an invalid value. Keep the height you want in a variable, and use that variable to produce a value for the style by adding "px" to it (or any unit you like). --- b { font-weight: normal; }

      C 1 Reply Last reply
      0
      • G Guffa

        The height attribute is a string value, that may contain something like "100px". If you add the value 22 to the string, the value will be converted to a string, and the result will be "100px22". This is of course an invalid value. Keep the height you want in a variable, and use that variable to produce a value for the style by adding "px" to it (or any unit you like). --- b { font-weight: normal; }

        C Offline
        C Offline
        CoolASL
        wrote on last edited by
        #3

        Hey Guffa, You are great man... I dont know how you always come to my rescue, be it C# or JScript. That solution indeed solved my problem. Can you please help me out in one more thing. Well, i continued making my script and found one strange thing. I have some DIVs, and their heights are being set by a CSS class. Now if you try to retrieve the height of any of the DIVs, the value returned is blank. I mean nothing is returned. Say, i tried:

        alert(f4.style.height);
        

        and this returned a blank alert. Just before this statement, i added a: f4.style.height = 22px; then when i tested, the alert showed the height as 22px. Is this behaviour normal, or am i going wrong somewhere ? Please help. Thanks in advance. *** Who said nothing is impossible? I have been doing it for a long time ***

        G 1 Reply Last reply
        0
        • C CoolASL

          Hey Guffa, You are great man... I dont know how you always come to my rescue, be it C# or JScript. That solution indeed solved my problem. Can you please help me out in one more thing. Well, i continued making my script and found one strange thing. I have some DIVs, and their heights are being set by a CSS class. Now if you try to retrieve the height of any of the DIVs, the value returned is blank. I mean nothing is returned. Say, i tried:

          alert(f4.style.height);
          

          and this returned a blank alert. Just before this statement, i added a: f4.style.height = 22px; then when i tested, the alert showed the height as 22px. Is this behaviour normal, or am i going wrong somewhere ? Please help. Thanks in advance. *** Who said nothing is impossible? I have been doing it for a long time ***

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          It's normal. The style that is set using a CSS class is not stored in the style property. You can use the currentStyle property to get the actual style that is the composite of default styles, css styles and inline styles. It's not part of the standard DOM, though. --- b { font-weight: normal; }

          C 1 Reply Last reply
          0
          • G Guffa

            It's normal. The style that is set using a CSS class is not stored in the style property. You can use the currentStyle property to get the actual style that is the composite of default styles, css styles and inline styles. It's not part of the standard DOM, though. --- b { font-weight: normal; }

            C Offline
            C Offline
            CoolASL
            wrote on last edited by
            #5

            Guru, you are simply marvellous. That indeed helped. Thanks again. *** Who said nothing is impossible? I have been doing it for a long time ***

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups