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

406
Vistas
How to check/uncheck checkbox by clicking outside specific block?

So I have a div that appears/disappears on clicking checkbox.


    <input type="checkbox" id="btn">
    <div id="box"></div>

    #box {
        display: none;
        width: 100px;
        height: 100px;
    }

    #btn:checked + #box
        display: block;
    }

But I also want to add an option to close it by clicking anywhere outside this box. How can I do it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Check the below code. You can use label for to achieve this behavior. You click a box outside of checkbox and it gets checked as you wanted.

label {
  display: block;
  margin-top: 100px;
  width: 200px;
  height: 200px;
  background: limegreen;
}

#btn:checked~#box {
  display: block;
}

#box {
  margin-top: 50px;
  display: none;
  width: 200px;
  height: 200px;
  background: red;
}
<input type="checkbox" id="btn">
<label for="btn"></label>

<div id="box">
</div>

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