By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,258 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,258 IT Pros & Developers. It's quick & easy.

Toggle elements of 2! divs.

Markus
Expert 5K+
P: 6,050
I've made the peice of code below to toggle the selected elements 'display' from 'display' to 'none' and vice versa. Now i'd like to know if it's possible for me to toggle the display elements of 2 IDs.

e.g. Click on one Div, that closes and another one opens.

Cheers :)

Expand|Select|Wrap|Line Numbers
  1. function toggle(theDIV){ 
  2. chStyle = document.getElementById(theDIV).style ; 
  3. if(chStyle.display == "block" || leStyle.display =="") { 
  4. chStyle.display = "none"; 
  5. else{ 
  6. chStyle.display = "block"; 
  7.  
Oct 14 '07 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
hi ...

simply use a list and loop through it:

Expand|Select|Wrap|Line Numbers
  1. var divs = { 'div_id1': 1, 'div_id2': 1 };
  2.  
  3. for (var i in divs) {
  4.     toggle(i);
  5. }
kind regards
Oct 15 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.