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.
Post History
The first item your selector returns is the top level arrow. hasAttribute just tells us if the attribute is present, not what the value is. So basically your condition is returning true for all ele...
Answer
#1: Initial revision
The first item your selector returns is the top level arrow. `hasAttribute` just tells us if the attribute is present, not what the value is. So basically your condition is returning true for all elements. Since that includes the top level element, it gets clicked and everything collapses. Try: ```js document.querySelectorAll(".CategoryTreeToggle").forEach( (element)=>{ if (element.getAttribute('data-ct-state') === 'collapsed' ) { element.click(); } }); ```