SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display block/none in a for loop

    How do you expand collapse (or toggle I should say) one div while making the others collapse?
    Code:
    function openThis(){
    	var thisExpand = new Array();
    		thisExpand[0] = "the_nav";
    		thisExpand[1] = "the_blog";
    		thisExpand[2] = "main_search";
    		thisExpand[3] = "addit_txtboxes";
    		thisExpand[4] = "spoke_listbox";
    		thisExpand[5] = "other_selections";		
    		thisExpand[6] = "66_books";
    
    		for(i=0;i<thisExpand.length;i++){
    			var expandThisOne = document.getElementById(thisExpand[i]);
    			if(expandThisOne.style.display == 'none'){
    			expandThisOne.style.display = 'block'; 
    			document.getElementById('minmaxbox_'+i).innerHTML = '[ - ]';
    			}else{
    			expandThisOne.style.display = 'none'; 
    			document.getElementById('minmaxbox_'+i).innerHTML = '[ + ]';
    			}
    		}
    	}
    This doesn't seem to work.
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you know which div to open? Are you passing a parameter into this function??
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •