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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:14:30+00:00 2026-05-29T05:14:30+00:00

How do I dynamically change the color (background and text) of a single select

  • 0

How do I dynamically change the color (background and text) of a single select menu in jQuery Mobile, without affecting other elements of the same class?
I’ve tried several ways, including:

$('#select').css({color:#000});

and

$('#select').removeClass('ui-btn-up-a').addClass('custom-class');  

I’ve also tried adding a refresh after it to no avail:

$('#select').selectmenu('refresh');

I’m trying to change the color based on the selected value, so I’m placing the code within the change event of the select menu like so

$("#select").live("change", function(event, ui) {
    ...
}

My HTML is as follows:

<select name="select" id="select">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

Any help on changing the text color or background color is appreciated!

  • 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-29T05:14:31+00:00Added an answer on May 29, 2026 at 5:14 am

    You can do this in this way:

    <!DOCTYPE html> 
    <html> 
        <head> 
        <title>Page Title</title> 
    
        <meta name="viewport" content="width=device-width, initial-scale=1"> 
    
        <link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
    <script>
      $("#page").live("pagecreate",function(){
    
            $("#select1").live( "change", function(event, ui) {
                switch($("#select1").val()){
                    case "1":
                        $("#fc .ui-select .ui-btn-up-c").removeClass('green red black').addClass('blue');
                        break;
                    case "2":
                        $("#fc .ui-select .ui-btn-up-c").removeClass('blue red black').addClass('green');
                        break;
                    case "3":
                        $("#fc .ui-select .ui-btn-up-c").removeClass('green blue black').addClass('red');
                        break;
                    case "4":
                        $("#fc .ui-select .ui-btn-up-c").removeClass('green red blue').addClass('black');
                        break;
                }
            });
    
            $( "#select1" ).selectmenu({
                create: function(event, ui){ 
                    $("#fc .ui-select .ui-btn-up-c").addClass('blue');
                }
            });
    
      });
    </script>
    
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <style>
    
     .blue{
        color:blue;
        background:cyan;
     }
     .green{
        color:green;
        background:coral;
     }
     .red{
        color:red;
        background:ivory;
     }
     .black{
        color:black;
        background:lavender;
     }
     </style>
    </head> 
    <body> 
    
    <div data-role="page" id="page">
    
    
        <div data-role="content">   
    
    <div data-role="fieldcontain" id="fc">
       <select name="select1" id="select1">
          <option value="1">Blue</option>
          <option value="2">Green</option>
          <option value="3">Red</option>
          <option value="4">Black</option>
       </select>
    </div>
        </div><!-- /content -->
    </div><!-- /page -->
    
    </body>
    </html>
    

    Let me know if that helps

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

Sidebar

Related Questions

I am trying to dynamically change the font and background color of my app
How to change the background color of a view dynamically? Do I set a
Possible Duplicate: Change custom color for Rectangle.Fill or Grid.Background I'm trying to dynamically set
How can I dynamically change the background color of a button in Tkinter ?
I wan't to change the background color of a div dynamicly using the following
I am developing a single web application that will dynamically change its content depending
I'm using the After Effects CS3 Javascript API to dynamically create and change text
I'm trying to dynamically change a Border Background property named Brush2, but I get
I'm writing code this week to dynamically change the color of images. As long
I have following textview in my Activity. I want to change the background color

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.