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

191
Views
how to toggle using onclick attribute of HTML

So, I have created a clickable div by putting onclick=" " attribute of HTML, it allows me to show my custom modal, now on my custom modal I have created another div with onclick, both divs has the same function on it like onclick="open__instruments()".

to better understand the structure, i have attached a code:

 <div class="w-full h-10 flex gap-2 relative" onclick="open__instruments()" id="creates__area">
      <div class="w-full h-full shrink-0 rounded-lg text-green4 hover:text-blue-text bg-white shadow-shadow1 flex justify-center items-center gap-2 hover:bg-green2 select-none">
          <span class="material-symbols-rounded">add</span>
          <div class="w-fit h-fit font-semibold py-2.5 ">Create</div>
      </div>
      <div class="w-[11rem] p-1 bg-white shadow-xl h-fit absolute -right-[11.7rem] rounded-lg hidden" id="instruments">
         <div class="w-full h-10 text-gray-600 rounded-md left_flex pl-3 hover:bg-green2 hover:text-blue-text font-semibold cursor-pointer" onclick="open__instruments()">New Area</div>
         <div class="w-full h-10 text-gray-600 rounded-md left_flex pl-3 hover:bg-green2 hover:text-blue-text font-semibold cursor-pointer mt-1" onclick="open__instruments()">New Parameter</div>
         <div class="w-full h-10 text-gray-600 rounded-md left_flex pl-3 hover:bg-green2 hover:text-blue-text font-semibold cursor-pointer mt-1" onclick="open__instruments()">New Task</div>
      </div>
 </div>

and it looks like this:

enter image description here

when I click that it will show the modal I created:

enter image description here

Now when i click New Area or New Parameter or New Task in my modal, the modal won't close, but when i click the +create div/button it will hide the modal.

below is the javascript function of onclick="open__instruments()":

const open__instruments = ()=>{
    if(document.getElementById('instruments').classList.contains('hidden')){
        document.getElementById('instruments').classList.remove('hidden')
    }else{
        document.getElementById('instruments').classList.add('hidden')
    }
}

how am i able to hide the modal by clicking a menu/button/div in my modal? BTW, i have also created separate function for toggling the modal but it still doesn't work, also, there is no error in the console.

about 4 years ago · Juan Pablo Isaza
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!