By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

How do you REALLY toggle visibility in Netscape (using 7.1 right now)

P: n/a
Hi,

I've read through quite a number of postings on here so far and have
seen what look like very simply, reasonable answers to this question,
however I am still completely unable to do what I want to do.

I just want to know how I should toggle the visibility of divs in
Netscape (I'm using 7). For example, say I have the following HTML
code:
<a href='javascript:showMyDiv();'>Show mydiv</a>

<div id='mydiv' style='visibility:hidden;'>
This text does not appear when I load the page in Netscape, so I know
it recognizes the 'visibility:hidden;' part of the above tag.
</div>

However, when I click on the link (coded as above), the following
javascripts do not make the div appear. It works fine in Explorer.
<script>
function showMyDiv()
{
mydiv.style.visibility = "visible"; // Works in IE, not Netscape
document.mydiv.style.visibility = "visible"; // Ditto

// THE FOLLOWING WERE SUGGESTED, BUT NONE OF THEM WORK FOR ME
document.mydiv.style.visibility = "show";
document.mydiv.visibility = "show";
document.mydiv.style.visibility = "visible";
document.mydiv.visibility = "visible";
document.mydiv.display = "";
document.mydiv.style.display = "";
}
</script>

Can anyone tell me what the syntax really SHOULD be?

Eternal thanks in advance.

- Jon
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jonathan wrote:
<a href='javascript:showMyDiv();'>Show mydiv</a>

<div id='mydiv' style='visibility:hidden;'>

However, when I click on the link (coded as above), the following
javascripts do not make the div appear. It works fine in Explorer.

mydiv.style.visibility = "visible"; // Works in IE, not Netscape

Can anyone tell me what the syntax really SHOULD be?


document.getElementById('mydiv').style.visibility = 'visible';
Jul 20 '05 #2

P: n/a
Ivo
"Leif K-Brooks" wrote:
Jonathan wrote:
<a href='javascript:showMyDiv();'>Show mydiv</a>

<div id='mydiv' style='visibility:hidden;'>

However, when I click on the link (coded as above), the following
javascripts do not make the div appear. It works fine in Explorer.

mydiv.style.visibility = "visible"; // Works in IE, not Netscape

Can anyone tell me what the syntax really SHOULD be?


document.getElementById('mydiv').style.visibility = 'visible';


or even:
if( document.getElementById && document.getElementById )
{ document.getElementById('mydiv').style.visibility = 'visible'; }

Also, it may be worth repeating that 'javascript:' as the href of an <a> tag
should be avoided, unless you wish to present a bookmarklet. The link SHOULD
really look something like:

<a href="nojs.html" onclick="return showMyDiv();">Show mydiv</a>

and the function should explicitely return a boolean *false* value to stop
the href to the non-javascripted alternative resource being followed.
Better still is of course to dynamically document.write() the link to
prevent the javascriptless from seeing it in the first place.

--
Iv
Jul 20 '05 #3

P: n/a
Jonathan wrote:
<a href='javascript:showMyDiv();'>Show mydiv</a>
That's a rather bogus construct. What does this "link" do when js is
disabled? You're better off with "onClick" set to an element that is
only created via JavaScript. Thus, when it's disabled, there's nothing
there. When it's enabled, there's a button or some such thing that
toggles the visability of the div.
However, when I click on the link (coded as above), the following
javascripts do not make the div appear. It works fine in Explorer.

<script> function showMyDiv()


You've already got the answer you need. You might want to ask in a
javascript group next time, as this group is for html.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #4

P: n/a
Ivo wrote:
or even:
if( document.getElementById && document.getElementById )


Errrr.... huh? I presume there's a typo there, as:

A && A == A

--
Mark.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.