473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Expand/Collapse DIVS

Hi,

I'm using the following javascript function to expand and collapse portions
of text in a web page (targeted at IE5.5 and above):

function doExpand(paraNum,arrowNum) {
if (paraNum.style.display=="none") {
paraNum.style.display="";
arrowNum.src="collapse.gif";
}
else {
paraNum.style.display="none";
arrowNum.src="expand.gif";
}
}

Implemented as follows:

<p><a href="javascript:doExpand(exp1,ar1)"><img src="expand.gif" id="ar1"
border="0" width="9" height="9"></a>
Title Text</p>
<div id="exp1" style="display: none" onclick="doExpand(exp1,ar1)">
<p>Drop down text here</p>
</div>

And repeated when required in the same page after changing the paraNum and
arrowNum parameters.

Does anyone know how I could adapt the script to enable more than one set of
DIVs to be expanded at the same time... i.e.: with a link that says "Show
All" and when clicked, all collapsed text on the page is then exapnded...?

Thanks in advance for any clues...

James Hurrell
--
..
Jul 20 '05 #1
1 22563
function doExpandAll( objImage ) {
var boolExpandAll = (objImage.src == 'expand.gif'); // Sets boolean
to true when expand image is clicked
for ( var intArg = 1; intArg < arguments.length; intArg++ ) { // Loop
through all the arguments (ignoring first one, which is the image)
var objDiv = arguments[intArg]; // Create a reference to each
div object in turn
objDiv.style.display = (boolExpandAll) ? 'block' : 'none'; // If
expanding set to visible, else set to hidden
}
objImage.src = (boolExpandAll) ? 'collapse.gif' : 'expand.gif'; // If
expanding set to collapse-image, else set to expand-image
}

<p><a href="javascript:doExpand(ar1,exp1,exp2,exp3)"><im g
src="expand.gif" id="ar1" border="0" width="9" height="9"></a> Title
Text</p>
<div id="exp1" style="display: none">
<p>Drop down text here</p>
</div>
<div id="exp2" style="display: none">
<p>Drop down text here</p>
</div>
<div id="exp3" style="display: none">
<p>Drop down text here</p>
</div>
Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ireneatngs | last post by:
Hi, I have example html below which contains a couple of hidden divs. However, some of the table borders within these hidden divs are actually displayed when they should not be. In my...
1
by: Randy Starkey | last post by:
Hi, Is there a way to expand and collapse all if I have multiple implementations of this script on a single page? The script works well individually. Thanks! --Randy Starkey ---
4
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
1
by: Mel | last post by:
i am displaying the following (+ & - signs are images): + click on the sign to the left to expand after user clicks on the + sign - thanks for clicking item-1 item-2 item-3
0
by: Shadow Lynx | last post by:
When using ASP.NET 2.0's built-in TreeView on a page with <BASE target = "AnythingBut_Self"></BASE> in the HEAD, the expand/collapse buttons fail to function. The reason for this is that the...
2
by: sam | last post by:
Hi all, I have a series of divs in 2 blocks say BLOCK1 and BLOCK2 and I want to use one click to expand/collapse all those in each block. But the code I came up with exapands all the divs in the...
0
by: jim | last post by:
Hi, I have a TreeView control that sits on the MasterPage. All of my other webpages inherit from that Master Page. The Treeview receives it's data using an XMLDataSource that has it's DataFile...
4
by: Rabel | last post by:
I am not very good at javascript I mostly am a flash developer but I am trying to apply one of our old expanding menus to work for a new site but it doesn't collapse the way I need it to right now...
0
by: pbd22 | last post by:
Hi. I have two divs inside a containing div <div id=container> <div id=top> </div> <div id=bottom> </div> </div>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.