Expand/Collapse DIVS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Hurrell

    #1

    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
    --
    ..


  • Fred Basset

    #2
    Re: Expand/Collapse DIVS

    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
    fred.basset@who syourdaddy.com

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

    Comment

    Working...