473,800 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(paraNu m,arrowNum) {
if (paraNum.style. display=="none" ) {
paraNum.style.d isplay="";
arrowNum.src="c ollapse.gif";
}
else {
paraNum.style.d isplay="none";
arrowNum.src="e xpand.gif";
}
}

Implemented as follows:

<p><a href="JavaScrip t: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="doExpa nd(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 22594
function doExpandAll( objImage ) {
var boolExpandAll = (objImage.src == 'expand.gif'); // Sets boolean
to true when expand image is clicked
for ( var intArg = 1; intArg < arguments.lengt h; 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.di splay = (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="JavaScrip t: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
fr*********@who syourdaddy.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
1068
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 example, I have comments indicating that if I remove the 'border-collapse' attribute for two of the tables within the hidden divs, my problem is fixed.
1
3356
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
3403
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
1
1251
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
2559
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 hyperlinks generated for the expand/collapse buttons includes javascript code that will execute in the frame specified in the Base Target rather than the current document. To remedy this, TreeView should render a target="_self" attribute for each...
2
4664
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 entire page. How do I restrict it to each block and also how do I cllapse those in each block and change the text to Collapse All. I am stumped here. Any help really really appreciated. Here is my code. Thanks,
0
2426
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 property set to the Web.sitemap file. I have turned off the Expand/Collapse icons on the Treeview. I want to be able to single click a node in the tree view to
4
8359
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 the code I am using looks like this function openSubCategory(n, nn) { var i = 0 for(i=1;i<n+1;i++) { var sel = document.getElementById('insideSubCategory'+i); sel.style.display = 'none';
0
2472
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
9695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10287
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3770
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.