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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:38:12+00:00 2026-05-25T00:38:12+00:00

TL;DR: I’m using jQuery .css() to set the background color of an element, but

  • 0

TL;DR: I’m using jQuery .css() to set the background color of an element, but I need to preserve css’s :hover functionality.


I am using a jQuery plugin to enable imbedding images into a set of dropdowns. It does this by changing the dropdown options into a series of nested div and a elements with a good amount of additional styling. On my site, these dropdowns are used for selecting elements to customize the appearance of a product’s preview before customers make their purchase. The images added are thumbnails of the selections available to the customer.

That all works great, except that one of the customization options includes partially-transparent images (of black, gold, and silver) that are overlaid atop another customization. Basically no background color works to get them all to show up, so we are using jQuery to set the background color of the overlaid component to match the color of the item selected for the background component. Some will not show up well, but those will also show up poorly in the preview and in the final product, so it is fine if they look bad.

All of that works using this code:

function changeSelection(id, selection, color) 
{
    //other unrelated code

    //update color of overlay to match background selection
    if (id == "SelectBackground") {
        //update background color
        $("#SelectOverlay_title").css('background-color', color);
        $("#SelectOverlay_child > a").css("background-color", color);
        $("#SelectOverlay_child > a.selected").css("background-color", "#66CCFF");

        //update text color - white for dark backgrounds; black for light
        if ((color.substring(1, 2) > -1) && (color.substring(1, 2) < 7)) {
            $("#SelectInsignia_title").css('color', "#FFFFFF");
            $("#SelectInsignia_child > a").css('color', "#FFFFFF");
        } else {
            $("#SelectInsignia_title").css('color', "#000000");
            $("#SelectInsignia_child > a").css('color', "#000000");
            $("#SelectInsignia_child > a.selected").css("color", "#FFFFFF");
        }
    }
}

The problem, however, is that after applying these changes, the SelectOverlay a:hover css no longer fires to provide the customer with visual feedback about which selection they are currently over.

I briefly considered applying the changes through swapping out css classes instead of calling .css() but that becomes problematic when you consider the potential for dozens of different background colors, each of which is pulled dynamically from the database.

So…what can I do to preserve the SelectOverlay a:hover effects after changing the background color in jQuery?

  • 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-25T00:38:12+00:00Added an answer on May 25, 2026 at 12:38 am

    Instead of setting color/background-color as inline styles via .css(), you should use CSS classes. That way, #SelectOverlay a:hover will still be specific enough to work.

    The quick but naughty option is to use !important on every property that needs it inside #SelectOverlay a:hover.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I need to clean up various Word 'smart' characters in user input, including but
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.