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

Peter Brunone peter at brunone.com
Mon Nov 13 12:02:19 CST 2006


		   This has absolutely nothing to do with the topic of this thread, but are there any native Spanish speakers here, and if so, did you find the URL below rather shocking?

Distracted,

Peter

				From: "Pitre, Russell" RPITRE at shawmut.com

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

Hello.

I have a written a simple function to toggle the visibility of a 

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 
===============================================
Directories
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20061113/64d6acac/attachment.htm>


More information about the Javascript mailing list