Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:12:17+00:00 2026-05-28T16:12:17+00:00

I have 5 divs for example <div class=group id=div1>Div1</div> <div class=group id=div2>Div2</div> <div class=group

  • 0

I have 5 divs for example

<div class="group" id="div1">Div1</div>
<div class="group" id="div2">Div2</div>
<div class="group" id="div3">Div3</div>
<div class="group" id="div4">Div4</div>
<div class="group" id="div5">Div5</div>

Then I have a select control:

<select id="mySelect">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

Then what I want to do: when “3” is selected in mySelect control, I want to display the first 3 divs, when “5” is selected, I want to display all divs. Additionally, the initial value of select is for example “2”, then when a page is load, I want to display first 2 divs. How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:12:18+00:00Added an answer on May 28, 2026 at 4:12 pm

    Assuming the divs are in the order of the options, you could use the :lt() selector jQuery offers:

    $('.group').hide();
    $('#mySelect').change(function () {
        $('.group').hide();
        $('.group:lt(' + ($(':selected', this).index()+1) + ')').show();
    });
    

    You could then add the following code to select the second one on load:

    $('#mySelect option:eq(1)').prop('selected', true).trigger('change');
    

    Here’s the edited fiddle. This has the (in my opinion pleasant) side-effect of not having to use ID’s at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to follow divs: <div id=cont> <div class=row> <div class=col>1</div> <div class=col>example.com</div> <div
I have a list of DIVs, like this : <div id=list> <div class=classA classB
I have 2 main div's. Group1 and group2. Those group divs contain other 2
I have three divs : <div id=login /> <div id=content /> <div id=menu />
I have three DIVs, something like this: <div id=header> ... </div> <div id=content> <div
I want to insert all divs which have the class .page into an array,
I have a series of divs of the same class; some with title attributes
I have a jQuery script that will display specific divs depending on which select
I have a markup like this: <div class=classA classB>the content</div> What I would like
I have <div class='line'> <div class='chord_line'> <span class='chord_block'></span> <span class='chord_block'>E</span> <span class='chord_block'>B</span> <span class='chord_block'>C#m</span>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.