Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts

    tree node toggle

    I'm putting together a javascript folder tree but I do not want more than one node expanded at a time. Below is the working function I've put together but I have no idea how to code it to close previous nodes when opening a new one. Any advice would be appreciated! Thanks

    var _image_dir = new Image();_image_dir.src="img/fe.gif";
    var _image_diropen = new Image();_image_dir.src="img/fc.gif";
    var _image_item = new Image();_image_dir.src="img/d.gif";
    function setExpandedIco(id){var i=document.getElementById(id+'_image');i.src='img/fe.gif';}
    function setCollapsedIco(id){var i=document.getElementById(id+'_image');i.src='img/fc.gif';}
    function toggleNode(id){if(toggleLayer(id+'_subitems'))setExpandedIco(id);else setCollapsedIco(id);}
    function toggleLayer(id){var l=document.getElementById(id);var s=l.style||l;if(s.visibility=='hidden'){s.visibility='visible';s.display='block';return true;}else{s.visibility='hidden';s.display='none';return false;}}

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    One solution is to build another function to collapse all and call it first at the begining of the expand function's code lines.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •