Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

351
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda