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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:46:22+00:00 2026-06-12T00:46:22+00:00

I have a container <div> into which I dynamically insert third-party content over which

  • 0

I have a container <div> into which I dynamically insert third-party content over which I have NO control, in other words, I get what I’m given.

If the inserted element on the third-party website had a hover state I have already stored that hover color as a hex color; I can’t store it as a style, as this color variable is updated dynamically.

What I want to be able to do is apply that hover color variable to the element that’s landed inside my container.

I can make it work if I code the style in advance, but, as I said, I don’t know it in advance so I can’t do so. This simple code does work, giving the link an orange hover state. (See my working fiddle.):

<style>
    .hovering, #container a:hover {color: orange;}
</style>
<script>
    $('#container').hover(function() {
        $(this).addClass('hovering');
    }, function() {
        $(this).removeClass('hovering');
    });
</script>

<div id="container">
    <a href="something">
        some link
    </a>    
</div>    

However, I have to use the stored hover color variable hoverClass and apply it, but I can’t get it to work. I tried this but it’s not working. (See the fiddle I’m trying to make work.):

<script>
    var hoverClass = '.hovering, #container a:hover {color: orange;}';
    $('#container').hover(function() {
        $(this).addClass(hoverClass);
    }, function() {
        $(this).removeClass(hoverClass);
    });
</script>
<div id="container">
    <a href="something">
        some link
    </a>    
</div>    
  • 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-12T00:46:23+00:00Added an answer on June 12, 2026 at 12:46 am

    .hovering, #container a:hover {color: orange;} is not a class, its a CSS rule.

    If you need the colour to be a variable, I recommend changing to the following:

    <script>
        var hoverColour = "orange";
        $('#container a').hover(function() {
            $(this).css("color", hoverColour);
        }, function() {
            $(this).css("color", "auto");
        });
    </script>
    <div id="container">
        <a href="something">
            some link
        </a>    
    </div>  
    

    Alternatively, a simplier solution would be to add the style using jQuery:

    $(function(){
        var hoverColor = "orange";
        $("head").append("<style type='text/css'>#container a:hover { color: " + hoverColor + "; }</style>");
    });
    

    — WORKING FIDDLE —

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

Sidebar

Related Questions

problem shown: http://test.aussieclubroom.com/test.html I have a div in which content is dynamically generated into.
I have a div which has no content. the content is dynamically loaded into
OK so I have a container div that loads some content which is generated
I have Resorts.aspx which loads content from ResortProducts.ascx into a div via Ajax. Resorts.aspx
I have a container div (red) with a top padding of 400px. The content
I have a container DIV which contains several block-DIVS. Every block-DIV contains SPAN items
i have a container div which is position:relative and the squares are position:absolute because
I'm with a little problem. I have the container div for some elements which
I have a div Container, and I am creating a dynamic textbox control when
I have a container div tag which wraps an image named tray which provides

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.