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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:10:07+00:00 2026-06-05T22:10:07+00:00

I am working on some code, basically I have a form. On that form

  • 0

I am working on some code, basically I have a form. On that form is a select option where I want users to select a font color.
I then need to append that option to an element on page, by adding the option they chose as a css class. Need to do this live.

So form element like so:

<select id="selectcolor" name="selectcolor" style="width: 200px;">
                        <option value="null">-- Select a Color ... --</option>
                        <option value="black">Black</option>
                        <option value="white">White</option>
                </select>

JS I made is:

//select text color
    $("#selectcolor").change(function(){
    var color = $(this).val();
    $(".selectcolor").css("color", 'color');

HTML to apply change to:

<div class="rightBottom selectcolor">Change this text<br />color</div>

Then in css I was gonna do:

.black {color:#000;}
.white {color:#fff;}

etc.

Basically, when user changes the select option, lets say to black, the class attribute changes text color to black on the div / span elements. Etc

Any suggestions please, I tried adding in select option values color:#000 etc but didnt work, I am guessing theres a couple of issues I am overlooking…

Thankyou in advance

  • 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-05T22:10:09+00:00Added an answer on June 5, 2026 at 10:10 pm
    $('#selectcolor').change(function() {
        var color = this.value || '';
        $('.selectcolor').attr('class', function(i, classes) {
            var cls = classes.split(/[\s]/);
            cls[2] = color;
            return cls.join(' ');
        });
    });
    

    DEMO

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

Sidebar

Related Questions

here is some code I've been working on, basically I need to set up
I have some working code that uses IImgCtx to load images, but I can't
So far, I have some working code that goes into a list of servers
So basically this code was working fine before. I had some computer issues and
I'm working some code that inserts csv rows into an SQLite database using Python.
I am working on some code that filters text before it is sent further
I'm trying to get a .toggleClass working on a form that I have multiple
I have an ancient webpage that I need to instill some databasing capabalities into
I was working on some code recently and came across a method that had
I have been working on some jQuery code for an interactive map. I've already

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.