In a webpage there are three clickable elements, all sharing the same class (.CategoryTreeToggle).
Clicking on button A shows button B and clicking on button B shows button C.
An HTML example would be any MediaWiki category tree with three or more branches, such as here.
I think the setInterval function is not the best approach.
In your mediawiki example, there’s a single action attached to all the bullets.
Each bullet has a data-ct-state=“collapsed” attribute.
Clicking the bullet toggles the data-ct-state to “expanded”.
Then you just have to show/hide the children, with a script or CSS depending on your HTML structure. E.g;, span[data-ct-state="collapsed] ~ div.category{diaply:none;}