Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

323
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda