[Javascript] "display none" to all children

Michael Borchers list at tridemail.de
Thu May 31 02:40:32 CDT 2007


Thanks guys.
Unfortunately the subsheets are created dynamically and there can be several 
with unknown names.
That's why I will have to loop through the child nodes.
But using a class name instead of directely using 'style.display' feels 
nice.

I now changed my script and it works similar to my script before.


function showContactsSheets(sheet) {
 var contactsSheetsDiv = document.getElementById('contactsSheets');

 if (contactsSheetsDiv.hasChildNodes()) {
     // Get all children of node
     var children = contactsSheetsDiv.childNodes;

     // Loop through the children
     for(var c=0; c < children.length; c++) {
      children[c].className = 'contactsSheetsHide';
     }
 }

 if(sheet != '') {
  if(document.getElementById(sheet)) {
   // Show container
   contactsSheetsDiv.className = 'contactsSheetsBlock';

   // Show sheet
   document.getElementById(sheet).className = 'contactsSheetsBlock';
  }
 }
}

div.contactsSheetsHide {
 display: none;
}

div.contactsShow {
 display: block;
} 




More information about the Javascript mailing list