943,945 Members | Top Members by Rank

Ad:
May 16th, 2005
0

Hide all DIV's On Click

Expand Post »
Hello all:

I'm creating an image gallery that opens in hidden divs. Here's my javascript code:

<script type="text/javascript">
<!--
function popupSwitch(szDivID, iState)
{
if(document.layers)
{
document.layers[szDivID].visibility = iState ? "show" : "hide";
}
else if(document.getElementById)
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState ? "visible" : "hidden";
}
else if(document.all)
{
document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
}
}
// -->
</script>

If the user clicks on this link

<a href="javascript:;" onClick="popupSwitch('popup1',1);" value="Show Div"><img src="images/exterior1_th.jpg" width="127" height="89" border="0"><br>Exterior Photo One</a>

it displays this div:

<div id="popup1" class="popup">
<div align="center"><img src="images/exterior1.jpg"><br>
<b><a href="javascript:;" onClick="popupSwitch('popup1',0);" value="Hide Div"><font size="2">Close
Window [X]</font></a></b><br>
</div>
</div>

As you can see, when the user clicks "Close Window" it will hide the div.

Here's what I'm having trouble with:

if the user clicks on another link to show another DIV without closing the previous one, I need a fuction that will hide all DIV's that might be visible.

I'm a little stumped on this one. Help :-)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RustyShock is offline Offline
1 posts
since May 2005
May 18th, 2005
0

Re: Hide all DIV's On Click

Create an array. Store the ID of the DIVs into that array when the user makes them visible.

Each time they click a link to make a div visible, iterate through the array, toggling all the other divs.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript, Form fields validation and submit
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Dynamically modifying the CSS attributes through Javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC