473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Toggle elements of 2! divs.

Markus
6,050 Expert 4TB
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
1 1369
gits
5,390 Expert Mod 4TB
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

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

Similar topics

3
by: Jürgen Heyn | last post by:
Good morning, on form 2 input elements and 1 image are placed. The 1st (Index) one is "hidden", the 2nd ) is an empty textbox. When clicking the picture I would like to toogle a boolean value....
4
by: Dave Benjamin | last post by:
Is there anything I can do to fully justify DIVs or IMGs without resorting to JavaScript? I'd like to do what "text-align: justify" does with text, but it doesn't seem to work with anything else....
9
by: hobosalesman | last post by:
Somehow font elements are being added everywhere in my page, with size set to 4. Maybe I'm just tired but I have no idea what's going on, even weirder considering the page is XHTML 1.0 strict...
1
by: swiftouch | last post by:
I'm getting an error message in FF2.0: document.getElementById(toggle) has no properties The goal of the script is, when I hover my mouse over an image, to make one div element visible while...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.