Collapses/Expands the node - Node.js DOM

Node.js examples for DOM:Node

Description

Collapses/Expands the node

Demo Code


/**/*from   www  .j  av a  2 s .  c om*/
 * Collapses/Expands the node
 * @param ele
 */
function toggleNodes(ele){
  var divE = (hasClass(ele,'e') ? ele : findParentByClassName(ele,'e'));
  //don't toggle self-closing elements
  if (!hasClass(divE.firstElementChild,'nsc')) {
    var divC = divE.getElementsByClassName('c')[0];
  
    if (divE.className.indexOf('hidden') > -1){
      var spanClosed = divE.getElementsByClassName('closed')[0];
      divE.removeChild(spanClosed);
      divC.style.display='';
      divE.className = divE.className.replace(' hidden','');
    }else{
      divC.style.display='none';
      divE.className += ' hidden';
      var closed = createNodeStructure('http://www.w3.org/1999/xhtml','span','class','closed','...');
      divC.parentNode.insertBefore(closed,divC);
      }
  }
}

Related Tutorials