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

185
Visualizações
jQuery onclick function only works for the first element

I have a select option with an <a> link like this:

<select id="varUsage" class="form-control">
    <option value="weight">Weight</option>
    <option value="color">Color</option>
    <option value="quality">Quality</option>
</select>

<a id="submitUsage" class="btn btn-primary btn-lg">Add</a>

Now I made this onclick function for when users click on Add:

$("#submitUsage").click(function(){
    var selectedUsage = $("#varUsage").val();
    $('#' + selectedUsage).removeAttr( 'style' );
});

So it basically picks the value of select input as selectedUsage variable and removes the style attribute of a div that has same id value.

So basically the default overview of divs goes like this:

<div id="weight" style="display:none">
....
</div>

<div id="color" style="display:none">
....
</div>

<div id="quality" style="display:none">
....
</div>

Now this function works fine only for id="weight" div. So when users choose Weight option from select menu list, the div with of weight appears properly on screen.

But this does not work for the other two options and their related divs are still hidden when they're selected.

So what's going wrong here?

How can I properly show custom div when it's selected in select option and then user pressed on the Add link?

about 4 years ago · Juan Pablo Isaza
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