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

  • Home
  • SEARCH
  • 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 9169855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:56:10+00:00 2026-06-17T15:56:10+00:00

say i have the classes: .box { background:red; } .box .mini-box { background:green; }

  • 0

say i have the classes:

.box {  background:red; }
.box .mini-box { background:green; }

.box.active {  background:purple; }
.box.active .mini-box { background:yellow; }

if i was using css-transitions i would simply add transition:all 0.5s ease; and when the class active is added both elements would animate appropriately.

If I apply the jQuery toggleClass with an animation time, (without any css-transitions enabled) it only animates the targeted element. (i.e. .box).

$('.box').toggleClass('active', 500);

This does not happen with jquery ui’s toggleClass method when i apply it to the parent method. Is there a way to make it behave as the css transitions would?

You can see the problem here: http://jsfiddle.net/yg8rz/1/
Second (mini) box is not transitioning colours.

You can see the desired result here: http://jsfiddle.net/yg8rz/4/
You must be using a webkit browser for it to work (in this instance).

NOTE: In the interests of better css practice (leaning towards a future without javascript transitions) it is important that the elements inherit the active class from ancestors rather than directly applying an active class to any child elements.

It’s also important that this solution use javascript so that is works in ie8+

  • 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-17T15:56:11+00:00Added an answer on June 17, 2026 at 3:56 pm

    The problem you are experiencing is caused by .mini-box (judging from your selectors) being inside of .box. When you apply transition to your .box element, it works as it should, but your .mini-box is not selected at all by your .box.active .mini-box selector, because .box does not have .active class until transition completes.

    You can make an workaround like this

    HTML:

        <div class="box">normal 1</div>
        <div class="box">
            normal 2
            <div class="box mini-box">
                mini
            </div>
        </div>
    

    CSS:

    .box {  background:red; }
    .box .mini-box, .box.mini-box { background:green; }
    
    .box.active {  background:purple; }
    .mini-box.active { background:yellow; }
    

    Fiddle: http://jsfiddle.net/yg8rz/3/

    You will need to apply transition to both .box and .mini-box elements, I changed css classes so the same jQuery code also selects mini box and adds .active to it too.

    It is either this, or adding css transitions to your classes. You can cover all (major) browsers with:

    -webkit-transition: all 0.5 ease;
    -moz-transition: all 0.5 ease;
    -o-transition: all 0.5 ease;
    transition: all 0.5 ease;
    

    You can make only non-transition-supporting browsers use javascript with Modernizr:

    $(".box").toggleClass("active");
    if(!Modernizr.csstransitions){
        $(".mini-box").toggleClass("active", 500);
    }
    

    http://jsfiddle.net/yg8rz/10/

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

Sidebar

Related Questions

Say i have these classes ViewA and ViewB In objective C using the delegate
Let's say I have some classes like: <div class=something style=display: none>Some text I would
Say I have the following classes Box and Item. Where a box contains many
Say I have two classes in my CSS, say .classA{} and .classB{} , and
Say I have classes class A{ //code for class A } class B{ //code
Say I have two classes and have a requirement that the primary key property
Say you have two classes, A and B. Is it possible to instantiate both
Say I have two classes created work and workItem. CWorker *work = new CWorker();
Say I have two classes, and neither of them are GUI components. Class A
Say you have two classes, order and customer: public class Customer{ public int CustomerId

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.