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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:17:50+00:00 2026-05-24T18:17:50+00:00

I have a drop down box I am using to change CSS using jQuery

  • 0

I have a drop down box I am using to change CSS using jQuery

I have set up a series of CSS classes to use.

Two of my CSS classes also contain a :before class

Using jQuery, if I select one of the items in the box that use the :before option, there is no problem.

When I select the other CSS that uses the :before option, it is ignoring the :before part of the CSS when its displaying it.

If I choose the CSS with the :before, then choose one that doesnt use the :before, then switch to the other one, it is fine, it’s just when I am switching from one CSS with :before to another CSS with :before

the jQuery I am using for changing the CSS looks like this:

  $("#colour").change(function () {
      var str = "";
      $("select.col option:selected").each(function () {
            str = $(this).val();
          });

          var currClass = $('#heading').attr('class');

          $('#heading').addClass(str);
          $('#heading').removeClass(currClass);

    })

Am I doing something wrong that is causing it not to load the :before after each selection?

  • 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-24T18:17:51+00:00Added an answer on May 24, 2026 at 6:17 pm

    The each() logic looks wrong, only a single value, of select.col‘s options, is being used.

    Change the code to:

    $("#colour").change (function () {
        $('#heading').removeClass ();   //-- Clears all classes
    
        $("select.col option:selected").each ( function () {
            var str = $(this).val();
            $('#heading').addClass (str); // Add desired classes back, one at a time.
        } );
    } );
    

    Other than that, we need to the the relevant CSS and HTML, to help with any additional problems — like that IE-only behavior that you mentioned.

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

Sidebar

Related Questions

Does someone knows how can I change the container for my drop down box?
I have an html table of data with a drop down box in each
I'm trying to create a select box drop down with a twist, Basically this
I'm using ajax to update a textbox once the value in a drop down
I am trying to change the selected option in a select dropdown box with
I have the jquery code below that returns a list of ID's like this
I am trying to change my comboboxes to use autocomplete so i leverage the
I have a combo box inside a list view. And different items (rows) in
I have a live search facility that narrows down results in a table as
I'm trying to create a drop down menu where when you hover over the

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.