In the previous part of this two-part tutorial, I began describing how to build a bulleted menu of links, such as you might see on many web sites. These links unfold, so that some headings, when clicked, reveal links below them to pages that are subcategories. In this second part, I will jump right back into the subject, starting with the JavaScript code we need to accomplish the magic.
Completing a Bulleted Menu Of Links - Still on Second Level Event (Page 4 of 5 )
Note that the list blocks are nested. All of the expandable LI elements call the previously-described function, through the “splitID(ID)” function. When you click a second level LI element, the parent LI element also receives the click. So the above function is called first by the second level LI element and automatically by the parent first level element, without the user knowing.
We need to prevent the call from the parent LI element from having any effect. The second innermost block we have just talked about handles the click from a second level LI element. The former innermost block we talk about handles the click from a first level LI element. Just before the former innermost block does its work, the condition SndLBullet == false has to be satisfied.
Again, as the function is called twice, the expandOrCollapse() function is called first by the second level LI click. So the second innermost block is executed first, and not the first innermost block. While it is executed, it sets the SndLBullet variable to true.
When the expandOrCollapse() function is called again, because the parent first level LI received a click automatically, the first innermost block is supposed to be executed. However, it would not be executed because the condition SndLBullet == false would not be satisfied, since SndLBullet is true.
Well, just after the first innermost block, under the rightIDpart.length == 1 condition, the SndLBullet variable is set to false (the initial value) again. So if the user clicks a first level LI element, its corresponding innermost block will not be prevented from being executed.