Expand/Collapse DIVS

J

James Hurrell

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
 
F

Fred Basset

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)"><img
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top