472,954 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Remove space between hidden DIVs in Internet Explorer

I want to use JavaScript when a button is clicked to show and hide a
SPAN or DIV. This works in both IE and Netscape, but what I'd like to
happen is for there to be no white space where the hidden div is.

I start with two visible divs and in between them are two more hidden
ones...in Firefox this works fine--the two visible ones are right next
to each other, the button fires the script and the other div shows up
in the middle. Another button hides the div and the original two move
back together without space between them.

However on IE the two visible divs are separated by the amount of
whitespace that would be needed if the two hidden divs were actually
visible. They show and hide correctly, but the whitespace remains.
How can I fix this?

Thanks in advance!

Below is the code I'm using:

<style type="text/css">
..hidden
{
background:white;
height:0px;
overflow:hidden;
}
..fullsize
{
background:white;
}
</style>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
function toggle(id){

if (ns4){
document.layers[id].className =
(document.layers[id].className=='hidden') ? 'fullsize' : 'hidden';
}else if (ie4) {
document.all[id].className = (document.all[id].className=='hidden')
? 'fullsize' : 'hidden';
}else{
var divID = document.getElementById([id]);
divID.className = (divID.className=='hidden') ? 'fullsize' :
'hidden';
}

}
// Show/Hide functions for non-pointer layer/objects
function show(id) {
if (ns4){
document.layers[id].visibility = "show";
toggle(id);
}else if (ie4){
alert('ie4 fired');
document.all[id].style.visibility = "visible";
toggle(id);
}else{
var divID = document.getElementById(id);
divID.setAttribute('style', 'hidden:false');
toggle(id);
}

}

function hide(id) {
if (ns4){
document.layers[id].visibility = "hide";
toggle(id);
}else if (ie4){
document.all[id].style.visibility = "hidden";
toggle(id);
}else{
var divID = document.getElementById([id]);
divID.style.visibility = 'hidden';
toggle(id);
}
}
</SCRIPT>

Jul 23 '05 #1
1 12049
ta****@gmail.com wrote:
I want to use JavaScript when a button is clicked to show and hide a
SPAN or DIV. This works in both IE and Netscape, but what I'd like to
happen is for there to be no white space where the hidden div is.
Change the span/div display attribute:

spanRef.style.display = 'none'; // hides the span
spanRef.style.display = ''; // displays the span

Need to do some feature detection first, see below.

[...] <style type="text/css">
.hidden
{
background:white;
height:0px;
overflow:hidden;
}
.fullsize
{
background:white;
}
</style>
You may still need these for old Netscape, but otherwise you
don't need them any more.


<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
The language attribute is depreciated and replaced by the type
attribute. Just delete the language attribute.
function toggle(id){
if (ns4){
document.layers[id].className =
(document.layers[id].className=='hidden') ? 'fullsize' : 'hidden';

[...]

Don't use tabs in your code when posted here - replace with one
or two spaces. Manually wrap your code at about 65 characters
to allow for a couple of re-posts without wrapping.

Don't use browser detection, use feature detection - and test
for the most widely supported feature first. The following code
toggles an element between hidden and shown, tested in IE,
Firefox and Netscape 7.2.

You will need to add support for old Netscape and maybe really
old IE if you want.

<script type="text/javascript">
function toggle(id) {
if (document.getElementById) {
var el = document.getElementById(id);
} else if (document.all) {
var el = document.all(id);
} else if (document.layers) {
var el = document.layers[id];
}

if (el.style) {
if (el.style.display == 'none'){
el.style.display='';
} else {
el.style.display='none';
}
} else {
// browser does not support style object,
// hide some other way
}
}
</script>
<button onclick="toggle('aSpan');">toggle</button>
<span id="aSpan">a span</span>
[...]

--
Rob
Jul 23 '05 #2

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

Similar topics

2
by: Adam Siler | last post by:
i want to display a series of inline, fixed-width DIVs that will wrap into columns - a table, basically. i can do it under Internet Explorer, but the same code under Netscape or Opera does not...
13
by: Aaron | last post by:
Hi, In the following code, everything looks fine on Explorer, but on Netscape there is a large white gap between the 'top' section and the 'bottom menu' section. I've set the style 'div img...
2
by: D. Alvarado | last post by:
Hello I have 5 divs, and initially the lower 4 are hidden. I would like everything beneath the 5th div to appear flush against the first visible div. But right now, there is a gap of white...
10
by: web_design | last post by:
I'm making a form that is hidden until someone clicks on a link to open it. I can hide the form, but there is just a large white space on the screen where the form is hiding. Is there any way to...
7
by: Steve | last post by:
string str ="\"C:\Program Files\Internet Explorer\iexplore.exe\" -nohome" How can I remove charcter to string str = ="C:\Program Files\Internet Explorer\iexplore.exe -nohome"
3
by: Michael Singer | last post by:
I wrote a simple testprogramm which renders a hidden input field. the value of this field is dynamically generated and filled with 100000 "z"'s --> "zzzzzzzzzzzzzzzzzzz..." and so on. if i...
4
by: Andreas Prilop | last post by:
How many spaces should be displayed in A <span style="display:none">x</span> B between "A" and "B"? I notice that Mozilla displays one space and Internet Explorer (5 & 6) displays two spaces....
0
mighty
by: mighty | last post by:
Hi people having a slight problem witn my web page and internet explorer 6 I have a transparent flash file in a div called flash box which is in my header div and its pushing my navbar down...
2
by: esteuart | last post by:
I need to get the right combination for a div to clip any text inside and allow vertical alignment. I only have this problem in FireFox. I have 3 divs nested within each other. The outer div has...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.