Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS: Visibility and Display 2

Status
Not open for further replies.

Ascalonian

Programmer
Jan 4, 2008
264
US
OK, here is an odd question:

Is there a point to using both visibility AND display together? For example:
Code:
var someDiv = document.getElementById("someDiv");
someDiv.visibility="hidden";
someDiv.display="none";

I understand the difference between the two but I am looking at someone else's code and saw they used both together and made me think about it more.

Is there any drawback to this?
 
Without the bigger picture we can only guess.

This might a Javascript portion of some DHTML, eg a menu treeview. While you could expand submenu items by using the display property of a submenu div only, there may be some unwanted effects you can prevent by first setting display, then visibility, or in this case of perhaps visibly correctly collapsing that submenu div by setting both properties. It may also be a cross browser issue, that is solved this way.

Bye, Olaf.
 
Olaf is correct when he says that it may well be to circumvent a specific issue (e.g. browser-specific rendering bug).

However, assuming a perfect world where all browsers are equal, there's no reason to keep both lines - so unless you know of the reason they were both added, I'd ditch one or the other, depending on your needs.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
if he should ditch one, it should be visibility = 'hidden', because otherwise there will be empty space rendered which now is not done due to display='none', so the display='
none' is the more important one if both are used just because of the lack of knowledge what does what.´

There might be another reason if elements inside the div are set as visibility='inherit', which isn't available for the display property. Still it will only have an impact with DHTML and changes made to these properties at runtime.

Bye, Olaf.
 
Thank you all for your replies...

I am used to the typical toggleVisibility() where it just changed the display value.

But the code I am looking at now sets visibility first, then display. Which seems totally unneeded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top