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 4075858
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:21:07+00:00 2026-05-20T17:21:07+00:00

I have a drop-down and need to show hidden div that corresponds to the

  • 0

I have a drop-down and need to show hidden div that corresponds to the selected option and do nothing when a blank option is selected:

$("#hiddenDiv1").hide();
$("#hiddenDiv2").hide();

$('#mySelector').change(function() {

});

<select id="mySelector">
    <option>select one option</option>
    <option value="option1">option 1</option>
    <option value="option2">option 2</option>
</select>

<div id="hiddenDiv1">aaaaa</div>
<div id="hiddenDiv2">bbbbb</div>

That’s as far as I was able to get on my own.

  • 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-20T17:21:07+00:00Added an answer on May 20, 2026 at 5:21 pm

    An alternative to Emmanuel’s answer:

    var $div1 = $('#hiddenDiv1'),
        $div2 = $('#hiddenDiv2'),
        $both = $div1.add($div2);
    
    $('#mySelector').change(function() {
        var $this = $(this),
            val = $this.val();
    
        switch (val)
        {
            case 'option1':
                $div1.show();
                $div2.hide();
                break;
    
            case 'option2':
                $div1.hide();
                $div2.show();
                break;
    
            default:
                $both.hide();
        }
    });
    

    Edit

    Since there seems to be some desire to turn this into a bit of code golf, here’s my reduced-line-count version (no changes to the OP’s markup):

    var $hiddenDivs = $('div[id^=hiddenDiv]').hide();
    $('#mySelector').change(function() {
        $hiddenDivs.hide().filter('[id$=' + $(this).val().substring(6) + ']').show();
    });
    

    jsfiddle demo →

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

Sidebar

Related Questions

I have a drop down list that has options that need to be passed
I have this drop down where i need to show the years. I want
I have a drop down that I need to compare the values ( the
I need to show/hide options on one select drop down dependant on another select
I have a drop-down list that I need to capture the value of when
I have request where i need to change grid formatting on drop down action
I need a city/state/country Dynamic Drop-Down List in my Wordpress registration page. I have
I need some help please, I have a PHP page with a drop down
I am trying to build a drop-down menu that will show a row to
Basically what I need to know is this: I have to show a drop

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.