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

135
Views
Menu dropdown in html, css and js from mobile and desktop

i refer to this thread: JS using onclick event on li to display block

From desktop is ok but how do i do the same thing but that from the mobile you can touch the "disappearing" menu and make sure that it remains visible until the next touch?

I'm currently using this code here:

function dropdown() {
  document.getElementById("Menuitems").style.display = "block";
}
#dropdown ul {
  display: block;
  transition-duration: 1s;
}

#dropdown ul li {
  display: block;
  background-color: #212121;
  color: #ffffff;
}

#dropdown ul li ul {
  display: none;
}

#dropdown ul li:hover>ul {
  /*this is what the onclick event should do*/
  display: block;
}
<div id="dropdown">
  <ul>
    <li onclick="dropdown()"><a>Menu</a>
      <ul id="Menuitems">
        <li><a href="">item 1</a> </li>
        <li><a href="">item 2</a> </li>
        <li><a href="">item 3</a> </li>
      </ul>
    </li>
  </ul>
</div>

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

0

I just added an active class onclick .. the active class toggles on every click. and just add the same hover effect to active class

function dropdown() {
  document.getElementById("Menuitems").classList.toggle("active");
}
#dropdown ul {
  display: block;
  transition-duration: 1s;
}

#dropdown ul li {
  display: block;
  background-color: #212121;
  color: #ffffff;
}

#dropdown ul li ul {
  display: none;
}

#dropdown ul li:hover>ul,
#dropdown ul li>ul.active{
  /*this is what the onclick event should do*/
  display: block;
}
<div id="dropdown">
  <ul>
    <li onclick="dropdown()"><a>Menu</a>
      <ul id="Menuitems">
        <li><a href="">item 1</a> </li>
        <li><a href="">item 2</a> </li>
        <li><a href="">item 3</a> </li>
      </ul>
    </li>
  </ul>
</div>

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!