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

354
Vistas
Address CSS general sibling selector and input:checked

I've tried to address styles defined like this:

header input[type=checkbox] ~ div#example {max-height:0px;}
header input[type=checkbox]:checked ~ div#example {max-height:100px;}

I would like to do something like

document.getElementById('example').style.maxHeight='10px';
but it should only change
input[type=checkbox]:checked
not the unchecked Version.

Maybe there is a way with nextElementSibling? Thanx for your help!

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

0

You can reset the maxWidth when the input changes from unchecked to checked and vv.

document.querySelector('header input[type=checkbox]').addEventListener('change', function(event) {

  document.getElementById('example').style.maxHeight = event.target.checked ? '10px' : '0px';
});
header input[type=checkbox]~div#example {
  max-height: 0px;
}

header input[type=checkbox]:checked~div#example {
  max-height: 100px;
}
<header>
  <input type="checkbox">
  <div id="example"></div>
</header>

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