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

137
Vistas
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 Respuestas
Responde la pregunta

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 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