• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Javascript targeting the first element only with a double click issue

Resolved: Javascript targeting the first element only with a double click issue

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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!

javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Resolved: GLMM with quasi-Poisson distribution

24/03/2023

Resolved: Is it possible to do custom preinstall scripts for npm from which one is run depending on the environment?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.