/    Sign up×
Community /Pin to ProfileBookmark

Problem with visibility/display in Firefox

Hi

I am trying to create a basic menu where if you put your mouse over a button you get a bit of descriptive text or an image appearing somewhere else on the page. I have tried to do this with hiding/revealing hidden divs – works fine with IE but no others.

<html>
<head>
<script language=”javascript”>

var descriptions = new Array();
descriptions[0] = “<p>See whats been added to the web site recently</p>”;
descriptions[1] = “<p>Find out more about me</p>”;
descriptions[2] = “<p>Check out me links</p>”;

function showDescription(descriptionIndex)
{
if (document.all)
{
DescriptionDiv.style.visibility = “visible”;
DescriptionDiv.innerHTML = descriptions[descriptionIndex];
}
else
{
document.DescriptionDiv.visibility = “visible”;
document.DescriptionDiv.document.open();
document.DescriptionDiv.document.write(“<div class=’DescriptionDivStyle’>”);
document.DescriptionDiv.document.write(descriptions[descriptionIndex]);
document.DescriptionDiv.document.write(“</div>”);
document.DescriptionDiv.document.close();
}
}

function clearDescription()
{
if (document.all)
{
DescriptionDiv.style.visibility = “hidden”;
}

else
{
document.DescriptionDiv.visibility = “hidden”;
}
}
</script>

<style>

div {border-width:thin;border-style:ridge;border-color:red;width:250px;height:70px;visibilty:hidden;}

.DescriptionDiv {position:absolute;left:120px;top:50px;}

</style>
</head>

<body>
<a href=”whatsnew.htm” onmouseover=”showDescription(0)” onmouseout=”clearDescription()”><img src=”home_over.png” border=”0″></a>
<br />
<a href=”about.htm” onmouseover=”showDescription(1)” onmouseout=”clearDescription()”><img src=”about_over.png” border=”0″></a>
<br />
<a href=”links.htm” onmouseover=”showDescription(2)” onmouseout=”clearDescription()”><img src=”home_over.png” border=”0″></a>
<br />

<div id=”DescriptionDiv” name=”DescriptionDiv” class=”DescriptionDiv”></div>
</body>
</html>

Help please ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KDLAJan 11.2010 — Shouldn't this:

DescriptionDiv
be
<i>
</i>getElementbyID("descriptiondiv")


Also, this syntax seems off:
<i>
</i>document.DescriptionDiv.visibility = "visible";
document.DescriptionDiv.document.open();
document.DescriptionDiv.document.write("&lt;div class='DescriptionDivStyle'&gt;");
document.DescriptionDiv.document.write(descriptions[descriptionIndex]);
document.DescriptionDiv.document.write("&lt;/div&gt;");
document.DescriptionDiv.document.close();

You've got "document" in those strings twice, and what's the "open" for?

Normally, this would be the syntax:
<i>
</i>document.getElementbyId("descriptiondiv").style.visibility = "visible";

However, this looks like a mishmash of code, either for innerHTML or for a simple show/hide function.

I'd use CSS for this. Here's a start: http://psacake.com/web/jl.asp

For this:
<i>
</i>a.info:hover span{ /*the span will display just on :hover state*/
display:block;
position:absolute;
top:2em; left:2em; width:15em;
border:1px solid #0cf;
background-color:#cff; color:#000;
text-align: center}

I'd place it in the area you've already designated here:
<i>
</i>.DescriptionDiv {position:absolute;left:120px;top:50px;}
Copy linkTweet thisAlerts:
@gregcauthorJan 12.2010 — Thanks!!

I'm a bit of a noob when it comes to javascript and I've asked for help elsewhere but have had no replies as constructive as yours. I use html and css a lot but i must admit to gasping when you pointed out that css code could be used in this way (i must have lots still to learn!)

Am still going to experiment with javascript for this as well.

Thanks again - much appreciated ?
×

Success!

Help @gregc 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...