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

327
Views
When i click outside my element will not unvisible

i have got a div. If i click the show button the div vill be visible. I find a solution to hide div when i click outside the element, but it is not work, what i do badly?

function login_show(){
    let y = document.getElementById("login");
    if(!y.style.display || y.style.display == "none"){
        y.style.display = "block";
    }
    else{
        y.style.display="none";
    }}          
window.addEventListener("click", function(){
    if(!document.getElementById("login").contains(event.target)){
        document.getElementById("login").style.display="none";
    }
}); 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. You forgot the 'event' parameter in callback function.

  2. If the show button is outside of the div, you should consider it in the callback function, may be like:

    if(!document.getElementById("login").contains(event.target) && event.target !== document.getElementById("showButton"))

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!