How to grab all li elements from a ref() element? #9271
Replies: 1 comment
-
5 minutes after posting I find my mistake... of course! Damn it! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In my app, the menu is build dynamically after receiving some JSON from an API (stored in
navItems
). Once that is there, the elementdiv ref="navMenu" id="nav-menu"
gets populated with a 2-level menu using nestedul
andli
elements. UsingwatchEffect
I can check if the menu has been build and print the ref() to the console:Now I would like to apply some GSAP magic to each of the
li
elements. In order to do so I need to get all the li elements, but I do not know how. A simpleconst allListElements = Array.from(document.querySelectorAll('#nav-menu li'))
remains empty:What is the correct way in this case to grab all the list elements of that menu?
Beta Was this translation helpful? Give feedback.
All reactions