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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:44:53+00:00 2026-05-31T13:44:53+00:00

I have a project I am working on that needs to show/hide a division

  • 0

I have a project I am working on that needs to show/hide a division dependent on a selection.

I’m using the following code as my basis: (which can be seen working at http://jsfiddle.net/rtXLe/)

<select>
    <option value="#divA">a</option>
    <option value="#divB">b</option>
</select>

<div id="divA" class="brandDiv">brand A</div>
<div id="divB" class="brandDiv">brand B</div>

<script type="text/javascript">
    $(function() {
        $("select").change(function() {
            // hide all brands first
            $("div.brandDiv").hide();
            // val is something like #div1 or #div2
            var targetId = $(this).val();
            // show the new selected one
            $(targetId).show();
        });
    });         
</script>

My problem is that the values in the select box cannot be changed as they are dynamically created and reference something else, so they will be:

<select>
    <option value="3135">a</option>
    <option value="3136">b</option>
</select>

<div id="3135" class="brandDiv">brand A</div>
<div id="3136" class="brandDiv">brand B</div>

With that though there is obviously the hash tag missing from the value, which then isn’t able to be picked up by the jQuery.

What do I need to modify in the jQuery for the divisions to work?

  • 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-31T13:44:54+00:00Added an answer on May 31, 2026 at 1:44 pm

    Here it is Working: http://jsfiddle.net/jhRHg/5/

    HTML:

    <select>
        <option value="3135">a</option>
        <option value="3136">b</option>
    </select>
    
    <div id="3135" class="brandDiv">brand A</div>
    <div id="3136" class="brandDiv">brand B</div>
    ​
    

    JQuery:

    $("select").change(function() {
        // hide all brands first
        $("div.brandDiv").hide();
        // val is something like #div1 or #div2
        var targetId = $(this).val();
    
        console.log($(targetId).html());
        // show the new selected one
        $("#"+targetId).show();
    });​
    

    This will help, cheers!

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

Sidebar

Related Questions

I'm working on a project that needs to have a list of weekdays. I
On the project I'm working on, we have a file with svn:needs-lock that's frequently
I'm currently working on an app using MVVM that needs to have some data
I'm working on a project where I have 2 web services that need the
I have a project that I'm working on and I need to be able
I need to have an at-home project now that I'm working on Python/Django at
I have project that I'm working on that is going to require a webserver.
I have a project I'm working on that requires our WPF application read SMS
I have a project that I'm currently working on but it currently only supports
I have a project that I have been working on for a while, just

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.