473,563 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:whit e;
height:0px;
overflow:hidden ;
}
..fullsize
{
background:whit e;
}
</style>
<SCRIPT LANGUAGE="JAVAS CRIPT" TYPE="TEXT/JAVASCRIPT">
function toggle(id){

if (ns4){
document.layers[id].className =
(document.layer s[id].className=='hi dden') ? 'fullsize' : 'hidden';
}else if (ie4) {
document.all[id].className = (document.all[id].className=='hi dden')
? 'fullsize' : 'hidden';
}else{
var divID = document.getEle mentById([id]);
divID.className = (divID.classNam e=='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.visibili ty = "visible";
toggle(id);
}else{
var divID = document.getEle mentById(id);
divID.setAttrib ute('style', 'hidden:false') ;
toggle(id);
}

}

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

Jul 23 '05 #1
1 12089
ta****@gmail.co m 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.d isplay = 'none'; // hides the span
spanRef.style.d isplay = ''; // displays the span

Need to do some feature detection first, see below.

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


<SCRIPT LANGUAGE="JAVAS CRIPT" 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.layer s[id].className=='hi dden') ? '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.getEl ementById) {
var el = document.getEle mentById(id);
} else if (document.all) {
var el = document.all(id );
} else if (document.layer s) {
var el = document.layers[id];
}

if (el.style) {
if (el.style.displ ay == 'none'){
el.style.displa y='';
} else {
el.style.displa y='none';
}
} else {
// browser does not support style object,
// hide some other way
}
}
</script>
<button onclick="toggle ('aSpan');">tog gle</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
1920
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 behave as expected. the DIVs "collapse" into small rectangles (i put a border around them so i could see), but their contents (some middle-aligned text)...
13
2490
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 {display:block}' already to get rid on Netscape's problem with putting space around images, but it does nothing for this. Setting margins and padding...
2
2619
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 space between the first visible div, and everything beneath the 5th. Here is this code: <form name="f"> <div id="Item0">Item 1:<input type="text"...
10
1939
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 close the white space when the form is not showing? At the moment I'm using a <div> and hiding the visibility, and then making it visible when the...
7
22574
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
4212
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 call this page in IE and view the html source there are the 100000 z's
4
3573
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. See http://www.unics.uni-hannover.de/nhtcapri/temp/white-space.html for a cumulative effect. Why is this important? Instead of "span", think of...
0
1193
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 in internet explorer 6 , works fine in firefox and the latest explorer top right hand corner http://www.grange.oldham.sch.uk
2
15544
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 display of table, the first inner div has display of table-cell and the inner-most div has the text. The outer div has a set width and height. So...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.