Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
How can i coding multi level dropdown menu in javascript?

HTML CODES:

<nav class="menu">
    <a href="#"><button><i class="fi fi-rr-home"></i> Anasayfa</button></a>
    <div class="dropdownmenu">
        <button class="opener">Biz kimiz ? <i class="fi fi-sr-caret-down"></i></button>
        <div class="dropdownmenu-children">
            <a href="#">Hakkımızda</a>
            <a href="#">Takımımız</a>
        </div>                
    </div>
    <a href="#"><button>Çalışmalarımız</button></a>
    <div class="dropdownmenu">
        <button class="opener">Randevu Al <i class="fi fi-sr-caret-down"></i></button>
        <div class="dropdownmenu-children">
            <a href="#">Hakkımızda</a>
            <a href="#">Takımımız</a>
        </div>                
    </div>
</nav>

Javascript CODES:

const dropdownmenu = document.querySelectorAll(".dropdownmenu")

    dropdownmenu.forEach(element => {
    
        const button = document.querySelector(".opener")
        const submenu = document.querySelector(".dropdownmenu-children")
    
        button.addEventListener("mouseover",()=>{
    
            submenu.classList.add("active")
        })
        
        element.addEventListener("mouseleave",()=>{
        
            submenu.classList.remove("active")
        })
        
    });

With these codes, i can open "Biz kimiz ?" menu but i can't open "Randevu Al" menu. How can i prepare this property ? Could you please help me about this my problem ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are several issues here:

  • Some HTML tags have the same id (not allowed and produce issue)
  • In your Foreach loop, you do not use at all "element", so it basically has no effect.

What you should do in your loop is to get the DOM elements you want to attach events to, something like "const button = element.GetChild("button");"

Good luck :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!