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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:02:08+00:00 2026-06-11T22:02:08+00:00

Given this simple html, <select id=ddl> <option style=background:#0f0>a</option> <option style=background:#f00;>b</option> <option>c</option> </select> ( http://jsfiddle.net/DxK47/

  • 0

Given this simple html,

<select id="ddl">
    <option style="background:#0f0">a</option>       
    <option style="background:#f00;">b</option>   
    <option>c</option>
</select>

(http://jsfiddle.net/DxK47/)
You can see that each option has it’s own background colour.

Unfortunately, when whatever option is selected (causing the dropdownlist to ‘close’), the background remains white (or whatever the page default is).

Is it possible to have the background of the selected item be displayed in the dropdownlist after the selection has been made (ideally without using javascript)

  • 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-06-11T22:02:09+00:00Added an answer on June 11, 2026 at 10:02 pm

    Yes, is possible

    JS:

    $(function(){
        $("#ddl").on("change", function(){
            $("#ddl").css("background", $("#ddl option:selected").attr("style").replace("background:",""));
        });       
    });
    

    jsfiddle: http://jsfiddle.net/SnakeEyes/DxK47/3/

    and remove the ; from second option

    <option style="background:#f00;">b</option>

    to

    <option style="background:#f00">b</option>  
    

    Other solution: http://jsfiddle.net/SnakeEyes/DxK47/13/

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

Sidebar

Related Questions

This is probably pretty simple. I want to select all elements of a given
Here's a simple example to illustrate the behavior: Given this html markup: <div data-company=Microsoft></div>
This should be a simple one, but I'm a beginner with C#. Given a
Fairly simple; I'm just curious if there's a better way to accomplish this. Given
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
I have a simple html form like this <table> <tr><td >Topic: </td> <td> <input
Given this HTML - how can I extend my jQuery to make the text
I'm trying to use the jQuery UI to style my HTML select menu but
I am using this to get a list of elements from a webpage. http://www.gamespy.com/index/release.html
Given this simple class: class RenderResponseHandler(webapp2.RequestHandler): def __init__(self): self.nombreUsuario = obtenerUsuarioTablaUsuario().nombre if obtenerUsuarioTablaUsuario() else

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.