div style.height
-
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
-
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
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; }
-
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; }
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 *** -
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 ***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; }
-
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; }