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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:41:02+00:00 2026-05-30T07:41:02+00:00

I am trying to append a different id to options within select element. I

  • 0

I am trying to append a different id to options within select element. I can do this with images, but dont know how to do it with ID’s

Example: for images we use:

$(document).ready(function() {
$("#selectanimage").change(function() {
    var src = $(this).val();

    $("#masterPreview").html(src ? "<img src='" + src + "'>" : "");
});
});

The typical select would be:

<select id="selectanimage" name="selectanimage" style="width: 474px;" class="required">
<option value="null">--- Select your Image ... ---</option>
<option value="share/images/125x125blk.png">125px x 125px Black Background</option>
<option value="share/images/125x125wht.png">125px x 125px White Background</option>
<option value="share/images/180x100blk.png">180px x 100px Black Background</option>
</select>

What I want to do is .. change value in options to differenct class or id, and then get the js to switch accordingly.

So option value=”apple”
option value=”foo”

Im not sure if thats 100% clear lol

The objective is that the Div id masterpreview can contain the new class or id element of the option.

ie.

on click of option ( say someone clicked foo )

Then we would generate:

<div id="masterPreview">
   <div class="foo"></div>    
</div>
  • 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-30T07:41:03+00:00Added an answer on May 30, 2026 at 7:41 am

    If I understand you correctly (which quite frankly I doubt – your question is very confusing) you are saying that you want to have a select element where choosing different options will display different divs.

    You think this can be achieved by giving each option a value that is the class name of the div to be shown (where the actual div is contained by the div “masterPreview” elsewhere on the page), but you don’t know how to write the code to hide and show the corresponding divs when different options are selected.

    For the requirement as I have summarised it, here’s a working demo so that you can see if I’m even in the ballpark: http://jsfiddle.net/abw3T/

    If that’s remotely like what you want to do then this is how to code it:

    <style>
       #masterPreview > div { display: none; }
    </style>
    
    <select>
        <option value="none">--Please select--</option>
        <option value="apple">Apple</option>
        <option value="banana">Banana</option>
        <option value="carrot">Carrot</option>
    </select>
    <div id="masterPreview">
        <div class="apple">Apple Div</div>
        <div class="banana">Banana Div</div>
        <div class="carrot">Carrot Div</div>
    </div>
    
    <script>
    $("select").change(function(){
        $("#masterPreview > div").hide();
        $("." + $(this).val()).show();
    });
    </script>
    

    There’s really not much too it: on the change event for the select hide all any of the masterPreview’s child divs that might currently visible and then show only the one with the class name matching the value of the selected option.

    Note: you shouldn’t use classes to uniquely identify elements, that’s what the id attribute is for, but your sample div uses a class so I’ve stuck with that. The code would be exactly the same to do it with ids except for the line with .show() which would be:

    $("#" + $(this).val()).show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use this sample code from Microsoft to determine what encoder options
I am trying to append random numbers to different numbers of characters. Can anyone
I'm trying to append a string of svg elements to the dom. This is
I'm trying to append items to a QList at runtime, but I'm running on
I'm trying to re-append a removed option to the appropriate select option menu. I
I'm trying to use jQuery to append a row to a table and to
I am trying to use the .append function in jquery. I have a div
really struggling to resolve this issue. using nhibernate Im trying to join two different
I'm having headaches trying to make this work: I have a <a> element with
Im trying to compare two different string encoded by sha512. But, result is different.

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.