Toggle elements of 2! divs.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Toggle elements of 2! divs.

    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 :)

    [code=javascript]
    function toggle(theDIV){
    chStyle = document.getEle mentById(theDIV ).style ;
    if(chStyle.disp lay == "block" || leStyle.display =="") {
    chStyle.display = "none";
    }
    else{
    chStyle.display = "block";
    }
    }
    [/code]
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    simply use a list and loop through it:

    [CODE=javascript]var divs = { 'div_id1': 1, 'div_id2': 1 };

    for (var i in divs) {
    toggle(i);
    }[/CODE]
    kind regards

    Comment

    Working...