[Javascript] [Beginner] What is going on with my show/hide function?

Pitre, Russell RPITRE at shawmut.com
Mon Nov 13 11:42:43 CST 2006


Have you looked into scriptaculous?  

http://wiki.script.aculo.us/scriptaculous/show/CombinationEffectsDemo




-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Mark Kelly
Sent: Monday, November 13, 2006 12:28 PM
To: javascript at latech.edu
Subject: [Javascript] [Beginner] What is going on with my show/hide
function?

Hello.

I have a written a simple function to toggle the visibility of a <div>
that 
is, it seems to me, behaving oddly. On divs that are initially shown,
the 
function works perfectly, toggling the content visibility. On divs that 
are initially hidden, the first click appears to do nothing but 2nd and 
subsequent clicks work fine. The code seems to me (as a beginner to 
javascript but not programming) to be so simple I can't imagine what I'm

doing wrong.

I set the initial display value explicitly by setting the div class to 
either .shown or .hidden just to set the display property.

Any advice is appreciated.

Mark

===============================================
JAVASCRIPT
===============================================
function toggleDiv(divID) {
	myReference = getRefToDiv(divID);
	if(!myReference) {
	window.alert('Failed to get a reference to the named DIV');
	return;
	}
	if(myReference.style) {
		if(myReference.style.display != 'none') {
			myReference.style.display = 'none';
			} else {
			myReference.style.display = 'inline';
			}
		}
	}
===============================================
CSS
===============================================
.hidden {display : none;}
.shown {display : inline;}
===============================================
HTML 
===============================================
<a href="#" onClick="toggleDiv('nav-dir-table')" title="show/hide this 
list">Directories</a>

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list