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

  • SEARCH
  • Home
  • 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 7643495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:27:50+00:00 2026-05-31T09:27:50+00:00

I have a drop down list and 5 divs along with it.I need to

  • 0

I have a drop down list and 5 divs along with it.I need to show one particular div at one time and hide the other.This is my approach
This is my code

<div data-role="content">
    <div id="tab-1">
        <br />
        <div id="one" style="width: device-width; height: 150px;"></div>
        <div id="two" style="width: device-width; height: 150px;"></div>
        <div id="three" style="width: device-width; height: 150px;"></div>
        <div id="four" style="width: device-width; height: 150px;"></div>
        <div id="five" style="width: device-width; height: 150px;"></div>
        <div class="ui-select">
            <select name="usageDropDownList" id="usageDropDownList"
                data-native-menu="false" tabindex="-1">
                <option value="one">1</option>
                <option value="two">2</option>
                <option value="three">3</option>
                <option value="four">4</option>
                <option value="five">5</option>
            </select>
</div</div>

And here is my document.ready()

$(document).ready(function() {
    $("#usageDropDownList").change(function() {
        if ($(this).val() == 'one') {               
            $("#two").hide();
            $("#three").hide();
            $("#four").hide();
            $("#five").hide();              
            $("#one").show();
        } else if ($(this).val() == 'two') {
            $("#one").hide();
            $("#three").hide();
            $("#four").hide();
            $("#five").hide();              
            $("#two").show();
        } else if ($(this).val() == 'three') {
            $("#one").hide();
            $("#two").hide();
            $("#four").hide();
            $("#five").hide();              
            $("#three").show();
        } else if ($(this).val() == 'four') {
            $("#one").hide();
            $("#two").hide();
            $("#three").hide();
            $("#five").hide();              
            $("#four").show();
        } else if ($(this).val() == 'five') {
            $("#one").hide();
            $("#two").hide();
            $("#three").hide();
            $("#four").hide();              
            $("#five").show();
        }
    });
});

Can any one suggest me a better approach?

  • 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-31T09:27:52+00:00Added an answer on May 31, 2026 at 9:27 am

    This is all you need:

    $("#" + $(this).val()).show().siblings().hide();
    

    A breakdown:

    $("#" + $(this).val())  // selects div with id equal to value of selected option
    .show()                 // shows it
    .siblings()             // then selects all of the other divs next to it
    .hide()                 // and hides them
    

    Update:

    Since there is also the <div class="ui-select"> next to the “number” divs in your markup, that will also be hidden (which is undesirable). You can fix this in many ways, here are two:

    1: Make that div not be a sibling by simply placing a wrapper div around the “numbers”:

    <div> <!-- added this -->
      <div id="one" style="width: device-width; height: 150px;"></div>
      <div id="two" style="width: device-width; height: 150px;"></div>
      <div id="three" style="width: device-width; height: 150px;"></div>
      <div id="four" style="width: device-width; height: 150px;"></div>
      <div id="five" style="width: device-width; height: 150px;"></div>
    </div>
    

    2: Exclude the ui-select div specifically:

    $("#" + $(this).val()).show().siblings().not(".ui-select").hide();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 drop down list, one is college and other is branch, so
I have a drop down list that has options that need to be passed
I have this drop-down list of countries: <select name=country> <option value=>Country...</option> <option value=Afganistan>Afghanistan</option> <option
Ok so I have drop down list connected to a datasource, and I need
I have a drop down list box which has one of the values to
I have a drop down list that I need to react to asynchronously. I
I have a drop down list (select) populated from SQL. This is dynamic so
I have a drop down list. I want to add images along with it.
I have a drop down list's select tag that looks like this: <select name=MyName
I have a drop down list with two values (for now..) with other elements

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.