Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 15th, 2003, 09:42 AM
Authorized User
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Span tags not working Netscape

I am having problems with my the span tag display property. I am using the span tag to show or hide text in a form.
If <span id="name" STYLE="display:none"> then no text shows. If
<span id="name" STYLE="display: "> then the text shows.

This works fine in IE but in Netscape all my hidden text is showing. It seems that Netscape doesn't like the "display:none" style of the span tag. My JS function changes the display of the span tag based on the click of another field:

function ShowSpan()
if (document.studreg.service[0].checked)

This JS function does not work in Netscape but works fine in IE. Can you help please?
Old October 15th, 2003, 09:54 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

I haven't played much with the netscape DOM, but it might be a problem referencing the actual object.

In your function that changes the style, try:
and see if you get [object] or something like that in the alert box. If not, and you get undefined or null, then you'll know that it's a problem referencing the span object in the document.

You can try this to reference the object:
I beleive that is the syntax that works for both I.E. and Netscape. Again, to debug you can try:
to see if you get the object correctly.

Old October 15th, 2003, 10:10 AM
Authorized User
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts

I put document.getElementById('name').style.display=''; and that did the trick! It works in NS now.
Thanks Peter.

Old October 15th, 2003, 10:11 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

Try this, referencing elements by id is an IE only shortcut (Tested on Netscape 7.1):
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
  function hideShow()
    var spn1 = document.getElementById("spnShow"); 
    var spn2 = document.getElementById("spnHide");
    if (spn1.style.display == "inline")
      spn1.style.display = "none";
      spn2.style.display = "inline";    
      spn1.style.display = "inline";
      spn2.style.display = "none";    


<body bgcolor="#FFFFFF">
<input type="button" value="Hide/Show" onclick="hideShow();">
<span id="spnShow" style="display: inline">I should be visible</span>
<span id="spnHide" style="display: none">I should not be visible</span>

Old January 27th, 2005, 06:11 AM
Registered User
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts


Based on the same idea, how would you make an entire TR toggle its display when some text above the table is clicked? The TR should initially not appear when the page is first loaded. Should be compatible with Netscape. To make it just a bit more complicated, when the page loads, the text should read "view" and when the TR is visible, the same text should read "hide" (toggle). Thanks!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with <span> tag tclotworthy XSLT 2 February 18th, 2007 03:48 PM
Span Bug? interrupt HTML Code Clinic 4 June 20th, 2006 09:40 AM
HTML tags is not working in textarea in ASP.net suman9730 General .NET 1 May 23rd, 2006 04:48 AM
Dynamic content in Netscape not working. Help! nyc_courtney Javascript 2 August 25th, 2004 04:54 PM
span tag with code behind jtyson General .NET 3 April 22nd, 2004 02:50 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.