Short version: Is this the standard behavior that myDiv.style.display (Javascript) returns a myDiv.style.display value when I set div to display:none to the wizard’s stylesheet, but returns “none” when it is set via the inline style?
Long version:
I have several div that I hide and show through their display style, switching it with Javascript between block and none . They always start to hide ( display:none ), which I set using the built-in styles:
<div id="anID" class="aClass" style="display:none"> stuff </div>
Here is the Javascript for switching between none and block . The two chOpsXXX () functions simply set the value of divSection.style.display to the opposite value (along with another homework):
var divSection = document.getElementById("chOpsSection" + strSectionID); var strDisplay = divSection.style.display; if (strDisplay == "none") { chOpsDisplaySection(strSectionID); } else { chOpsHideSection(strSectionID); }
This all works great when I use the inline style attribute to set the initial display:none style.
I also set other styles for these divs in the wizard stylesheet. So I decided it made sense to move the initial state of display:none to the specified stylesheet. I have done it. I will not publish it, I think you can view it.
But when I did this, the div initially hidden ( display:none ), but the first call to divSection.style.display returns an empty string ( alert(strDisplay); returns an empty string, not null).
My Javascript shown above then hides it (because it is not equal to "none") and then calling next on divSection.style.display returns "none" and everything works fine from there. (The same behavior if I set it to inline in the wizard stylesheet: the div will be visible first, and the first call to divSection.style.display returns an empty string).
This is fairly easy to fix by checking both "none" and "" in my Javascript above. But I would like to know if this returning an empty string from divSection.style.display standard behavior.
All answers are welcome.
javascript css
John Fitzpatrick May 25 '13 at 10:54 2013-05-25 10:54
source share