/    Sign up×
Community /Pin to ProfileBookmark

show/hide div not working in IE

So I’ve got this script that shows/hides a div layer when you click on open or close. Now, it works perfect in Mozilla…BUT in IE, it shows the space where the hidden layer is? If that makes sense. Check out this page in Mozilla, and then in Internet Explorer.

[url]http://www.heartslie.com/fun/view2.html[/url]

Here is my code:

[code=html]<html>
<head>
<title>Spinner Example</title>

<style type=”text/css”>
body { font-family: arial, verdana, sans serif; width: 800px; }
.item-header a { font-size: small; }
.item-header {
font-weight: bold; border-bottom: 1px solid black;
font-size: x-large;
}
.item-body {
margin: 0px; font-size: small;
visibility: hidden; height: 0px;
}
</style>

<script>
function spin( obj )
{
var spinner = document.getElementById( obj );
var spinner_content = document.getElementById( obj+”_body” );
if ( spinner_content.style.visibility == ‘visible’ )
{
spinner.innerHTML = ‘open’;
spinner_content.style.visibility = ‘hidden’;
spinner_content.style.height = ‘0px’;
spinner_content.style.margin = ‘0px’;
}
else
{
spinner.innerHTML = ‘close’;
spinner_content.style.visibility = ‘visible’;
spinner_content.style.height = ‘auto’;
spinner_content.style.margin = ’20px 0px 20px 50px’;
}
}
</script>

</head>
<body>

<div class=”item-header”>
<a href=”javascript:spin(‘lev1’)”
id=”lev1″>open</a> Level One</div>

<div class=”item-body” id=”lev1_body”>
This is the content of level one.
</div>

<div class=”item-header”>
<a href=”javascript:spin(‘lev2’)”
id=”lev2″>open</a> Level Two</div>

<div class=”item-body” id=”lev2_body”>
This is the content of level two.
</div>

</body>
</html>[/code]

thank you in advance!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayMay 18.2006 — Try using display:none and display:block instead of visibility....
Copy linkTweet thisAlerts:
@SaveSheepauthorMay 18.2006 — Righteous idea man! Thank you!

So I took this code:
[CODE] if ( spinner_content.style.visibility == 'visible' )
{
spinner.innerHTML = 'open';
spinner_content.style.visibility = 'hidden';
spinner_content.style.height = '0px';
spinner_content.style.margin = '0px';
}
else
{
spinner.innerHTML = 'close';
spinner_content.style.visibility = 'visible';
spinner_content.style.height = 'auto';
spinner_content.style.margin = '20px 0px 20px 50px';
}[/CODE]


and replaced it with this:

[CODE] if ( spinner_content.style.display == 'block' )
{
spinner.innerHTML = '<img src=plus2.gif border=0>';
spinner_content.style.display = 'none';
spinner_content.style.height = '0px';
spinner_content.style.margin = '0px';
}
else
{
spinner.innerHTML = '<img src=minus2.gif border=0>';
spinner_content.style.display = 'block';
spinner_content.style.height = 'auto';
spinner_content.style.margin = '0px';
}[/CODE]



and it doesn't display right at all. You can check out the page again with these changes:

www.heartslie.com/fun/view.html

any other ideas?

also, whats the different between display:none and display:inline?
Copy linkTweet thisAlerts:
@TheBearMayMay 18.2006 — Looks right after you expand and collapse so the problem is in the initial style - probably have a few visibility:hidden in there somewhere.

display:none => don't display or reserve space

display:inline => treat as an inline element when displaying

display:block => treat as a block element when displaying
×

Success!

Help @SaveSheep spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...