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

110
Vistas
jquery simple hide show based on checkbox checked

I want to show and hide the options inside the main based on checkbox checked or not. I have many checkbox but here I am checking address checkbox.

This is my checkbox

<input type="checkbox" id="address">Mark it

here is div I want to hide/show

<div id="options">
//div
</div>

 if($('#address').prop('checked')){
        $('#options').show()
      }else{
        $('#options').hide()
      }

Above code is not working for me.

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

0

Your code will only work on the first time not every time the value of the checkbox changes.

You have to add event listener on change of the checked value of checkbox

$("#address").on("change", e => {
  const isChecked = e.target.checked;
  if (isChecked) $('#options').show()
  else $('#options').hide()
})

if ($('#address').prop('checked')) {
  $('#options').show()
} else {
  $('#options').hide()
}

$("#address").on("change", e => {
  const isChecked = e.target.checked;
  if (isChecked) $('#options').show()
  else $('#options').hide()
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="address">Mark it
<div id="options">
  //div
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

The reason your code not working, you only check the condition checkbox check or not you have to call the checkbox change event also every time when the checkbox gets clicked. here is a working demo hope it will help you to understand how jquery works.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
    $('#options').hide();
    $('#address').change(function () {
        if ($('#address').prop('checked')) {
            $('#options').show()
        } else {
            $('#options').hide()
        }
    });
});
</script>
</head>
<body>
<div id="options">
//div
</div>
<input type="checkbox" id="address">Mark it
</body>
</html>

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