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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:12:57+00:00 2026-05-18T20:12:57+00:00

I display 40+ boxes on a page: <div id=primary> <div class=box style=background:….> <a href=

  • 0

I display 40+ boxes on a page:

<div id="primary">
    <div class="box" style="background:....">
        <a href="" style="color:....">box1</a>
    </div>
    <div class="box" style="background:....">
        <a href="" style="color:....">box2</a>
    </div>
    ....
</div>

As you can see I set background-color and text-color. On hover I want to swap the colors:

      $(".box").each( function () {
          $(this).data('baseColor',$(this).css('background-color'));
          $(this).find('a').data('fontColor',$(this).css('color'));
          $(this).hover(function() {
            $(this).animate({ backgroundColor:
                       $(this).data('fontColor') }, 500);
          },function() {
            $(this).animate({ backgroundColor: 
                       $(this).data('baseColor') }, 1000);
          });
        });

The animation of the background-color works but I can not change the font color of the a element. Any ideas?

  • 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-18T20:12:58+00:00Added an answer on May 18, 2026 at 8:12 pm

    As @Brandon mentioned, you need jQuery UI (or something 😉 to animate non-integer properties.

    The bigger issue is the change of context in your each callback: inside the hover callback methods, the value of this won’t always be what you want. Also, creating new jQuery objects (with $(...)) is relatively expensive. Try:

    var cssBox = {
        backgroundColor: $('.box').css('background-color'),
        color: $('.box').css('color')
    };
    
    var cssLink = {
        backgroundColor: $('.box > a').css('background-color'),
        color: $('.box > a').css('color')
    };
    
    $(".box").each(function() {
        var $this = $(this),
            $this_a = $this.children('a');
    
        $this.data('baseColor', $this.css('background-color'));
        $this.data('fontColor', $this_a.css('color'));
        $this.hover(function() {
            $this.animate(cssLink, 500);
            $this_a.animate(cssBox, 500);
        }, function() {
            $this.animate(cssBox, 1000);
            $this_a.animate(cssLink, 1000);
        });
    });
    

    Demo here.

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

Sidebar

Related Questions

I display 40+ boxes on a page: <div id=primary> <div class=box style=background:....> <a href=
I want to display 4 or 5 boxes(vary) which occupy's 100% of the page
Is there any way I can direct display PDF files in modal boxes? I
How can I have this other box display at the bottom of the first
In my question form page, small boxes are display , i dont know what
Hi I am using JQuery to animate 2 div boxes on my page ,
a while back I ran across a situation where we needed to display message-boxes
I have 2 dialog boxes in which I will display 1 dialogbox at a
I use data binding to display values in text boxes in a C# Windows
'display the left product image if intImagePos = 2 then response.write(<td class=ProductImage> & vbcrlf)

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.