Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How to uncollapse an entire link tree with JavaScript?

Post

How to uncollapse an entire link tree with JavaScript?

+0
−0

This data tree is comprised of clickable buttons and I want to expose all branches, in a single action, instead of clicking each vertical arrow button anew.

I have tried the following code which didn't work (it will only toggle and untoggle the first and second branches).

document.querySelectorAll(".CategoryTreeToggle").forEach((element)=>{
    window.setInterval(()=>{
        if (element.getAttribute('data-ct-state', 'collapsed') ) {
            element.click();
        }
    }, 1000);
});

How to uncollapse an entire link tree with JavaScript?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Hint (4 comments)
Hint
Alexei‭ wrote almost 2 years ago

When clicking on a parent node, the child nodes are lazy-loaded (they do not exist in the DOM).

Initial state

<div class="CategoryTreeChildren" style="display:none"></div>

After clicking (abbreviated):

<div class="CategoryTreeChildren" style="">
   <div class="CategoryTreeSection">
       <div class="CategoryTreeItem">
                  <span class="CategoryTreeBullet">
                         <span class="CategoryTreeToggle CategoryTreeToggleHandlerAttached" data-ct-title="MediaWiki_as_a_content_management_system" data-ct-state="collapsed" title="expand"></span> 
                   </span> 
                       <a href="/wiki/Category:MediaWiki_as_a_content_management_system" title="Category:MediaWiki as a content management system">MediaWiki as a content management system</a>&lrm; 

I am into Vanilla JS, but I wonder if the function can "see" the newly created DOM elements.

deleted user wrote almost 2 years ago

I am sorry, I misunderstand how is the fact that the children are lazy loaded could help me expose the entire tree.

Alexei‭ wrote almost 2 years ago

Actually, it is just something I have noticed and that needs to be taken into account when looking for a solution. It makes things more complicated when compared to all nodes being in DOM, but hidden.

deleted user wrote almost 2 years ago

Oh, okay, I understand.