0

I have a structure that repeats recursively like this :

HTML: 

<!-- Root -->    
<div class="divRoot">

   <!-- Level 1, Item 1 -->
   <div class="divBranch">
      <!-- Toggle Trigger for following content -->
      <div class="divTrigger">
         <span class="lblName"> Level 1, Item 1 </span>
      </div>

      <!-- Level Two, Item 1 -->
      <div class="divBranch">
         <div class="divTrigger">           
            <span class="lblName"> Level 2, Item 1 </span>
         </div>

         <!-- Repeat the pattern as needed -->
      </div>
   </div>

   <!-- Level 1, Item 2 -->
   <div class="divBranch">
      <!-- Toggle Trigger for following content -->
      <div class="divTrigger">
         <span class="lblName"> Level 1, Item 2 </span>
      </div>

      <!-- Level Two, Item 2 -->
      <div class="divBranch">
         <div class="divTrigger">            
            <span class="lblName"> Level 2, Item 2 </span>
         </div>

         <!-- Repeat pattern as needed -->
      </div>
   </div>
</div>

I need to check if any items are visible in another branch when I am toggling an item in any branch. The items visibility is the additional selector filter. It has to be visible so I can find it and hide all items in another branch as the triggered branch is displayed.

I can't just chain up the tree until I hit root and start going back down to the others. I tried that and it slowed the page down dramatically locally. I don't even want to see what it does on a live site.

Another thought is to search the root element for descendants of class divBranch that are visible and not contained in trigger ancestors, descendants and is not itself, but I don't know how to do that.

Any suggestions of how to accomplish this?

Brett Weber
  • 1,839
  • 18
  • 22
  • It's pretty hard to understand exactly what you want. Can you set up a fiddlejs with what you have now? – vrijdenker Oct 02 '14 at 19:32
  • 2
    When you expand a particular branch, save a handle to that element in a variable. When you expand another one later, collapse the one already saved in the variable and so on.. i.e. no need to traverse at all if you never need more than one open branch at any point. – techfoobar Oct 02 '14 at 19:35
  • @vrijdenker I cannot right this minute. The html part was relatively quick to write, but the javascript code to display the issue would be a bit more time consuming. I was over complicating the process, anyways. It was as simple as keeping track of the current branch and when another branch is activated, the current one gets closed from level 1 up and the targetted one because current – Brett Weber Oct 02 '14 at 22:04

0 Answers0