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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:45:53+00:00 2026-05-30T09:45:53+00:00

I wish to avoid using css transitions. I have three divs of the same

  • 0

I wish to avoid using css transitions.

I have three divs of the same class. I’m attempting to toggle the background color of one div when clicked. When the div is clicked again, or one of the other are clicked, I wish it to return to default.

I have included the jQuery color plugin and succeded in changing the color on click. I belive that my conditions are wrong and thats why i cant change the color back when clicking the other div.

This is what i’ve done:

<script type="text/javascript">
jQuery(document).ready(function() {
    $('.link').click(function() {
        var $me = $(this);
        if ($me.css("background-color") == "#993") {
            $me.animate({backgroundColor:"#246"}, 500);
        } else {
            $(".link").each(function() {
                if ($(this) != $me) {
                    if ($(this).css("background-color") == "#246") {
                        $(this).animate({backgroundColor:"#993"}, 500);
                    }
                } 
            });
            $me.animate({backgroundColor:"#246"}, 500);
        }
    });
});
</script>
<style type="text/css">
.link {
    width:100px;
    padding:10px;
    background-color:#993;
    float:left;
    display:inline;
    text-align:center;
}
</style>
</head>
<body>
    <div class="link">link</div>
    <div class="link">link2</div>
    <div class="link">link3</div>

I have had some trouble understanding the backgroundColor consept and hope for help. 🙂

Thanks!

  • 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-30T09:45:54+00:00Added an answer on May 30, 2026 at 9:45 am
    <script type="text/javascript">
    function animateBackgroundColor() {
        $('.foo').toggleClass('fooAct');
    }
    $(document).ready(function(){
        $('.foo').click(function (){
            animateBackgroundColor();
        });
    });
    </script>
    <style>
    div {
    height:200px;
    }
    .foo {
    transition: background-color 2s;
    -moz-transition: background-color 2s; /* Firefox 4 */
    -webkit-transition: background-color 2s; /* Safari and Chrome */
    -o-transition: background-color 2s; /* Opera */
    background-color: red;
    }
    .fooAct {
    background-color:blue;
    }
    </style>
    <div class="foo"></div>
    

    Try this. CSS3 could help if you want to use css as well.

    There are 3 divs and when you click one of them, it will become blue. When you click other divs, blue is gonna red and clicked one is gonna blue. If you gonna click blue, It will become blue back.

    <script type="text/javascript">
    function animateBackgroundColor(obj) {
        $(obj).toggleClass('fooAct');
        $('.fooAct').not(obj).removeClass('fooAct');
    
    }
    $(document).ready(function(){
        $('.foo').click(function (){
            animateBackgroundColor(this);
        });
    });
    </script>
    <style>
    div {
    height:100px;
    margin-bottom:10px;
    }
    .foo {
    transition: background-color 1s;
    -moz-transition: background-color 1s; /* Firefox 4 */
    -webkit-transition: background-color 1s; /* Safari and Chrome */
    -o-transition: background-color 1s; /* Opera */
    background-color: red;
    }
    .fooAct {
    background-color:blue;
    }
    </style>
    <div class="foo"></div>
    <div class="foo"></div>
    <div class="foo"></div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return
I have created an ERD (Entity-Relationship Diagram) using ArgoUML and I wish to create
I wish to avoid os.walk, i am using a recursive function to read files
I wish to know if there is any way to avoid to have a
I wish to know all the pros and cons about using these two methods.
I wish to implement a 2d bit map class in Python. The class would
I wish I were a CSS smarty .... How can you place a div
Without using p/invoke, from a C++/CLI I have succeeded in integrating various methods of
I wish to have two threads. The first thread1 occasionally calls the following pseudo
I have a resource /system/resource And I wish to ask the system a boolean

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.