Question:
I’m learning JavaScript at the moment (started 3 weeks ago at college) and i’m struggling to create a mobile menu whereby you click and that reveals or hides a hidden menu.The issue here is that JS only targets the first class and not all of them. And you need to click twice to reveal the element that does work.
I would be very grateful for some guidance, and hopefully an expiation to help me understand the problem.
Thank you
Answer:
You have to find all nodes which match the selector.querySelectorAll
is used for that. Then you must loop through all the nodes and set the event.
Also, you have to remove the wrong closing <li>
tag (which messes up the selector) after </a>Text</a>
in the second menu-item-has-children
If you have better answer, please add a comment about this, thank you!