473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

display or visibility ?

I want to toggle a <div in and out of view.
My question, which of the below examples would best be supported.
Or is there another approach, that would be better used..TIA..

..A..
<a href="#" onclick="C1.style.visibility='visible';">open</a>
<a href="#" onclick="C1.style.visibility='hidden'">close</a>

..B..
<a href="#" onclick="C1.style.display='block'">display</a>
<a href="#"
onclick="C1.style.style.display='none'">none</a>

..C..
<a href="#"
onclick="document.getElementById('C1').style.visib ility='visible'">open</a>
<a href="#"
onclick="document.getElementById('C1').style.visib ility='hidden'">close</a>

..D..
<a href="#"
onclick="document.getElementById('C1').style.displ ay='block'">display</a>
<a href="#"
onclick="document.getElementById('C1').style.displ ay='none'">none</a>

Aug 5 '05 #1
4 25046
Els
wasntme wrote:
I want to toggle a <div in and out of view.
My question, which of the below examples would best be supported.
Or is there another approach, that would be better used..TIA..

.A..
<a href="#" onclick="C1.style.visibility='visible';">open</a>
<a href="#" onclick="C1.style.visibility='hidden'">close</a>

.B..
<a href="#" onclick="C1.style.display='block'">display</a>
<a href="#"
onclick="C1.style.style.display='none'">none</a>

.C..
<a href="#"
onclick="document.getElementById('C1').style.visib ility='visible'">open</a>
<a href="#"
onclick="document.getElementById('C1').style.visib ility='hidden'">close</a>

.D..
<a href="#"
onclick="document.getElementById('C1').style.displ ay='block'">display</a>
<a href="#"
onclick="document.getElementById('C1').style.displ ay='none'">none</a>


Neither of the above supported on any of my browsers with JavaScript
off I think?

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Aug 5 '05 #2
dc********@webtv.net (wasntme) wrote:
I want to toggle a <div in and out of view.
My question, which of the below examples would best be supported.
Or is there another approach, that would be better used..TIA..


I can't comment on the scripting aspect (not my forte), but
visibility:hidden is rather different to display:none, when you toggle
visibility the element remains part of the flow, hence it takes up
screen space, if you set display to none then the element is removed
from the flow.

--
Spartanicus
Aug 5 '05 #3
dc********@webtv.net (wasntme) wrote:
I want to toggle a <div in and out of view.


onclick="this.style.visibility='hidden'; return false;"
onclick="this.style.visibility='visible'; return false;"

or

onclick="this.style.display='none'; return false;"
onclick="this.style.display=''; return false;"

For display vs. visibility, see Spartanicus' reply.

Bye,
Martin
Aug 5 '05 #4
wasntme wrote:
I want to toggle a <div in and out of view.
My question, which of the below examples would best be supported.
Or is there another approach, that would be better used..TIA..

.A..
<a href="#" onclick="C1.style.visibility='visible';">open</a>
<a href="#" onclick="C1.style.visibility='hidden'">close</a>
Presumably 'C1' is the id or name of some element. If so, the above
script uses Microsoft's invention of making ids and names global
variables. Reference your elements some other way (e.g. as you've
done for C & D below) if you want to support those browsers that
conform to W3C standards (which includes IE 5.5 onward).

.B..
<a href="#" onclick="C1.style.display='block'">display</a>
<a href="#"
onclick="C1.style.style.display='none'">none</a>
A elements are not block by default, they're inline. The best method
is to use 'none' and ''. Setting display to the empty string will let
it return to its default or whatever has been set in a style rule
somewhere.

.C..
<a href="#"
onclick="document.getElementById('C1').style.visib ility='visible'">open</a>
<a href="#"
onclick="document.getElementById('C1').style.visib ility='hidden'">close</a>


Better, but not perfect. Not all browsers support the W3C's
getElementById, check the comp.lang.javascript FAQ for advice.

<URL:http://www.jibbering.com/faq>

Search clj for examples of 'showHide' scripts.

[...]
Aug 6 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: deepblue | last post by:
Hi, How to display a "Please wait" message in a webform when the webform is doing processing? The processing is initiated by user clicking a button. Thanks, Deepblue
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
1
by: VK | last post by:
visibility:hidden vs display:none I guess I *feel* the difference (or maybe not) Could anyone put it in words for me?
3
by: bitsyboffin | last post by:
Hi all, does anybody know of a bug in MacIE which prevents style.display = 'none' and style.visibility = 'hidden' from "sticking" in MacIE? I'm making some graphical checkboxes & radios (I know,...
15
by: Markus Ernst | last post by:
Hi When toggling an element on and off by setting its display property via DOM access, display:none is valid for all kinds of elements, but I can't find anything about a generic value for...
2
by: Jake Barnes | last post by:
Imagine I've this block of HTML: <p>Alex Schein Mailing List <input type="checkbox" name="newslettersToUse" value="133156"> (<a href="mcControlPanel.php"...
3
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is...
1
by: Summercool | last post by:
it seems that we can actually use "display" or "visibility" to implement tabs. i just wonder if there are pros and cons? it seems that if we use "display", the browser may need to shrink the 1st...
8
by: Haines Brown | last post by:
I want a hot text string to display an image only when hovered. In the body: .... <a id="link-a" href="#nogo"> <img id="photo" src="..." />hot text </a> ....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.