Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!