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

160
Vistas
How to hide/show a div id with jQuery when html option select is chosen

I have an html option select with two options:

<select name="subject" id="subject">
   <option value="option1">Option 1</option>
   <option value="option2">Option 2</option>
</select>

I also have a div element with id="human-genome".

<div id="human-genome"></div>

I want to hide this id by default and when option 1 is selected. I want to show this id when option 2 is selected.

Here is my Jquery:

   $(document).ready(function(){
  $("#subject").change(function(){
      if($(this.val() == 'option1'){
          $('#human-genome').hide();
      } else {
          $('#human-genome').show();
      });
   
});

For some reason, the code isn't working. Any suggestions? Thank you in advance!

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

0

There is a syntax error in the code you developed. I edited the code as follows to make it understandable.

enter image description here

$(document).ready(function(){
  $("#subject").change(function(){
    console.log(this.value);
    
    if(this.value == 'option1')
    {
      $('#human-genome').hide();
    }
    else
    {
      $('#human-genome').show();
    }
  });
});
#human-genome{
  margin-left: 100px;
  background-color: red;
  width: 100px;
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<select name="subject" id="subject">
   <option value="option1">Hide</option>
   <option value="option2">Show</option>
</select>

<div id="human-genome">TEST</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

enter image description here I just noticed a syntax error.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try use $(this).val() instead of your code please.

$(document).ready(function(){
    $("#subject").change(function(){
    if($(this).val() == 'option1'){
      $('#human-genome').hide();
    } else {
      $('#human-genome').show();
    }});});
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