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

117
Views
Display next closest div when current selected

Hello I want to show next div when current is selected for ex. when option 1 or 2 selected then drop down of 3 and 4 should be shown, and when 3 or 4 selected then drop down of 5 and 6 should be shown and so on...

Here's what i have done

$(document).ready(function () {
  var f = $('.abc').first().css("display","block");
  f.change(function() {
    f.next('.abc').css("display","block");
  });
});
.abc{
  display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="abc">
    <select>
        <option>1</option>
        <option>2</option>
    </select>
</div>
<div class="abc">
    <select>
        <option>3</option>
        <option>4</option>
    </select>
</div>
<div class="abc">
    <select>
        <option>5</option>
        <option>6</option>
    </select>
</div>
<div class="abc">
    <select>
        <option>7</option>
        <option>8</option>
    </select>
</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do it like this:

$(document).ready(function() {
  var f = $('.abc').hide();
  f.first().css("display", "block");
  f.change(function() {
    $(this).next('.abc').css("display", "block");
  });
});

First you want f to be equal to all .abc and not just the first.

Second you need $(this).next('.abc') and not f.next('.abc'). Because you want to know what abc has been changed so you know the next one.

Demo

$(document).ready(function() {
  var f = $('.abc').hide();
  f.first().css("display", "block");
  f.change(function() {
    $(this).next('.abc').css("display", "block");
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<body>
  <div class="abc">
    <select>
      <option>1</option>
      <option>2</option>
    </select>
  </div>
  <div class="abc">
    <select>
      <option>3</option>
      <option>4</option>
    </select>
  </div>
  <div class="abc">
    <select>
      <option>5</option>
      <option>6</option>
    </select>
  </div>
  <div class="abc">
    <select>
      <option>7</option>
      <option>8</option>
    </select>
  </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!