Intro section with dropdown navigation | CSS - Javascript - jQuery
Design comparison
Solution retrospective
Hi there,
Initially, I found the dropdown menu very challenging while trying pure javascript.
Because .querySelector
only chooses the very first element with the same class name, I could only control the first dropdown menu by id.
Then I turned to use jQuery, I use $(this)
to control which menu should be dropdown.
Still, I'd like to know how to achieve this feature with only JS. 🥲🥲
Community feedback
- @edesuccess54Posted over 2 years ago
use querySelectorAll to select all the element with the same class name then loop through each of them to add the event listener for the dropdown. better still utilize the idea of event delegation
Marked as helpful2@GretaLiPosted over 2 years ago@edesuccess54
Hi Ede, Thank you for your hints and inspired me to improve my solution!
I learned how to do dropdown by pure Javascript, also learned Event Delegation. :D
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord