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

136
Visualizações
selecting only the element in the same div with jquery

how can i selec only the element in the same div with jquery

$('.to-show').hide();

$('#offset').on('change', function() {
  if ($(this).val() == "Custom") {

    $(this).closest('.wrapper').children('.to-show').toggle();
  } else {
    $('.to-show').hide();
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
  <div class="to-click">


    <td class="value">
      <select id="offset" class="" name="attribute_offset" data-attribute_name="attribute_offset" data-show_option_none="yes">
        <option value="">Choose an option</option>
        <option value="15" selected="selected" class="attached enabled">15</option>
        <option value="Custom" class="attached enabled">Custom</option>
      </select> </td>


  </div>
  <div class="to-show">
    <div class="tc-cell tc-col-auto"><button type="button" class="button tm-section-link" data-title="Custom Offset" data-sectionid="61cc25f8bfe870.59019822">Custom Offset</button></div>

  </div>
</div>
<div class="wrapper">
  <div class="to-click">

    <td class="value">
      <select id="offset" class="" name="attribute_offset" data-attribute_name="attribute_offset" data-show_option_none="yes">
        <option value="">Choose an option</option>
        <option value="15" selected="selected" class="attached enabled">15</option>
        <option value="Custom" class="attached enabled">Custom</option>
      </select> </td>

  </div>
  <div class="to-show">

    <div class="tc-cell tc-col-auto"><button type="button" class="button tm-section-link" data-title="Custom Offset" data-sectionid="61cc25f8bfe870.59019822">Custom Offset</button></div>

  </div>
</div>

So this only work with first select option

How i can make it work with the second select option what i am missing here ?

i tried also $(this).closest('.wrapper').find('.to-show').toggle();

but that did not work

thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Having two elements with the same id is invalid html. Switch it to use class or another attribute. But you have a second problem with $('.to-show').hide();, it is always hiding both .to-show.

$('.to-show').hide();

$('.offset').on('change', function() {
  if ($(this).val() == "Custom") {

    $(this).closest('.wrapper').children('.to-show').toggle();
  } else {
    $(this).closest('.wrapper').children('.to-show').hide();
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
  <div class="to-click">


    <td class="value">
      <select id="offset" class="offset" name="attribute_offset" data-attribute_name="attribute_offset" data-show_option_none="yes">
        <option value="">Choose an option</option>
        <option value="15" selected="selected" class="attached enabled">15</option>
        <option value="Custom" class="attached enabled">Custom</option>
      </select> </td>


  </div>
  <div class="to-show">
    <div class="tc-cell tc-col-auto"><button type="button" class="button tm-section-link" data-title="Custom Offset" data-sectionid="61cc25f8bfe870.59019822">Custom Offset</button></div>

  </div>
</div>
<div class="wrapper">
  <div class="to-click">

    <td class="value">
      <select id="offset" class="offset" name="attribute_offset" data-attribute_name="attribute_offset" data-show_option_none="yes">
        <option value="">Choose an option</option>
        <option value="15" selected="selected" class="attached enabled">15</option>
        <option value="Custom" class="attached enabled">Custom</option>
      </select> </td>

  </div>
  <div class="to-show">

    <div class="tc-cell tc-col-auto"><button type="button" class="button tm-section-link" data-title="Custom Offset" data-sectionid="61cc25f8bfe870.59019822">Custom Offset</button></div>

  </div>
</div>

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