The :animated selector finds elements that are mid-animation when your query runs — slide, fade, show/hide, or custom .animate() effects. This tutorial covers the official jQuery demo, performance tips with .filter(), timing pitfalls, and when :animated does not apply.
01
Syntax
$(":animated")
02
Timing
Live snapshot
03
Effects
jQuery queue only
04
Combine
div:animated
05
Performance
.filter()
06
Since 1.2
Extension
Fundamentals
Introduction
Most jQuery selectors describe what an element is — a tag, class, or ID. The :animated pseudo-class describes what an element is doing right now: running a jQuery animation. Added in jQuery 1.2, it is one of several jQuery-specific extensions that do not exist in standard CSS.
Think of it as a snapshot. When you run $(":animated"), jQuery checks its internal animation registry and returns every element with an active effect. A moment later, when the animation completes, that same query may return nothing. This makes :animated perfect for debugging motion, highlighting moving panels, or guarding UI actions while transitions are in flight.
Concept
Understanding the :animated Selector
An element is animated in jQuery terms when a method from the effects module has started a transition and not yet reached its completion callback. That includes .slideToggle(), .fadeIn(), .hide("slow"), and .animate({ ... }).
Pure CSS transition or @keyframes animations do not register with jQuery — :animated will not find them. Likewise, a custom jQuery build stripped of the effects module cannot support this selector at all and will throw an error if you try.
💡
Beginner Tip
Click Run in the official demo while #mover is sliding — only then does $("div:animated") match and turn green. Click again when the div is still and nothing happens visually.
Foundation
📝 Syntax
Official jQuery API form (since 1.2):
jQuery
jQuery( ":animated" )
// shorthand:
$( ":animated" )
// combine with element types:
$( "div:animated" )
Parameters
:animated — no arguments; matches elements with a jQuery effect currently in progress.
Return value
A jQuery object containing zero or more animating elements at query time.
Both find animating elements — scoping with a CSS selector first is faster on large pages.
Global
$(":animated")
Every animating node on page
Tag combo
$("div:animated")
Official demo pattern
Filter
.filter(":animated")
Docs recommend this
Not matched
CSS @keyframes
jQuery queue only
Hands-On
Examples Gallery
Example 1 follows the official jQuery API demo. Examples 2–5 cover looping animations, performance filtering, timing checks, and stopping all motion. Use the Try-it links to run each snippet in the browser.
📚 Official jQuery Demo
Toggle a green class on any div that is animating when you click Run.
Example 1 — Official Demo: Toggle Class on div:animated
A div slides up and down forever. Click Run while it moves to add or remove the colored class on animating divs.
#mover slides up/down continuously (yellow → green when Run clicked mid-slide)
Static divs unchanged — they are not :animated
How It Works
animateIt() calls slideToggle("slow", animateIt), re-queueing itself when each slide finishes. On Run click, jQuery scans for divs with active effects — only #mover during motion — and toggles colored.
Example 2 — Recursive slideToggle Explained
Break down the loop so you see when :animated is true vs false.
jQuery
function animateIt() {
$( "#mover" ).slideToggle( "slow", function() {
// Callback runs when slide FINISHES — no longer :animated here
console.log( "Finished. Animated count:", $( ":animated" ).length );
animateIt(); // start next toggle
});
}
animateIt();
// During the slide (before callback): $( ":animated" ).length === 1
Only animating divs inside #stage get class "busy"
Rest of the page is never scanned for animation state
How It Works
:animated is a jQuery extension — browsers cannot accelerate it with native querySelectorAll. Narrow the candidate set with standard CSS selectors first.
Example 4 — Check :animated During vs After fadeIn
Log counts immediately after starting an effect and inside the completion callback.
Right after fadeIn call: 1
After fade completes: 0
How It Works
fadeIn enqueues an effect immediately, so the first log shows 1. When the fade finishes, jQuery clears animation state and :animated no longer matches.
Example 5 — Stop All Animations with $(":animated").stop()
Emergency brake: halt every running jQuery effect before starting new ones.
jQuery
$( "#stop-all" ).on( "click", function() {
$( ":animated" ).stop( true, true );
$( "div" ).removeClass( "colored busy" );
});
// stop(clearQueue, jumpToEnd)
// true, true — clear queued effects and snap to final state
All sliding/fading elements freeze immediately
:animated count drops to 0 — no elements mid-effect
How It Works
.stop(true, true) clears the effects queue and jumps to the end state. After stopping, $(":animated") returns an empty set until a new animation starts.
Applications
🚀 Common Use Cases
Debug dashboards — highlight $(":animated") during QA to spot runaway loops.
Disable buttons — block submits while $("#form").find(":animated").length is greater than zero.
Carousel guards — ignore next/prev clicks when slides are mid-transition.
Batch styling — add a busy class to animating cards for visual feedback.
Cleanup on route change — $(":animated").stop(true, true) before SPA navigation.
Teaching effects — official demo pattern for showing live animation state.
🧠 How jQuery Resolves :animated
1
Effect starts
A method like slideToggle registers the element in jQuery’s animation tracker.
Queue
2
Query runs
:animated checks which tracked elements are still in progress right now.
Snapshot
3
Return matches
Matched nodes become a jQuery object for chaining .toggleClass(), .stop(), etc.
Collection
4
▶
Effect ends
On completion, jQuery removes the element from the animated set — next query may return zero matches.
Important
📝 Notes
Available since jQuery 1.2 — a jQuery extension, not standard CSS.
Requires the effects module — slim custom builds throw without it.
Does not detect CSS transition or animation properties.
Matches only at query time — asynchronous; re-query if you need updated state.
Official performance tip: CSS selector first, then .filter(":animated").
Works with chained effects — an element stays animated until its current step completes.
Compatibility
Browser Support
The :animated selector ships with jQuery 1.2+ and the standard effects module. Browser compatibility follows your jQuery version — the selector itself has no separate native CSS support because it is a jQuery invention.
✓ jQuery 1.2+ · Effects module
jQuery :animated Selector
Works wherever full jQuery with effects runs — all modern browsers and legacy IE with supported jQuery builds. Not available in querySelectorAll or in slim jQuery builds without effects.
100%With jQuery + effects
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:animatedUniversal
Bottom line: Load full jQuery (not a slim effects-stripped build). For modern apps consider CSS transitions with class toggles — :animated is most useful when you already rely on jQuery effects.
Wrap Up
Conclusion
The jQuery :animated selector finds elements with active jQuery effects — a live snapshot, not a permanent property. The official demo pairs it with a looping slideToggle and a Run button that toggles colored on moving divs.
Remember the docs’ performance note: scope with CSS selectors, then .filter(":animated"). Skip it for CSS-only motion, and never use it in builds missing the effects module.
Use $("#container div").filter(":animated") on large pages
Query while you know an effect is running (mid-click, in callbacks)
Pair with .stop() to cancel runaway animation loops
Include the full jQuery effects module in your build
Combine with element types: $("div:animated")
❌ Don’t
Expect :animated to detect CSS keyframe animations
Run $(":animated") on every mousemove — it is a live scan
Use slim jQuery builds without the effects module
Assume zero results means animations are broken — they may be between cycles
Rely on :animated in new projects that use CSS transitions only
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :animated
Live snapshot of jQuery motion.
5
Core concepts
▶01
:animated
Mid-effect only
API
⏱02
Snapshot
Not permanent
Timing
⚡03
.filter()
Performance
Scope
🎨04
Effects
jQuery queue
Module
❌05
Not CSS
No @keyframes
Limit
❓ Frequently Asked Questions
:animated matches every element that is actively running a jQuery animation at the exact moment the selector executes. When the animation finishes, the element no longer matches until a new effect starts.
Any element with a jQuery effects queue in progress — .slideToggle(), .fadeIn(), .show('slow'), .animate(), and similar methods from the effects module. Pure CSS transitions or Web Animations API animations are not tracked by :animated.
jQuery tracks animation state internally when effects run. A custom slim build without the effects module has no animation registry, so :animated throws an error when used.
Because :animated is a jQuery extension, not standard CSS, it cannot use the browser's native querySelectorAll speed boost. Pick elements with a normal CSS selector first, then narrow with .filter(':animated').
Yes. Combine tag names with the pseudo-class: $('div:animated') matches only div elements that are animating. The official demo uses $('div:animated').toggleClass('colored').
Only while the slide animation is running. In the official recursive slideToggle demo, #mover matches during each transition and stops matching when the slide completes and before the next toggle begins.
Did you know?
jQuery also provides :hidden, :visible, and :focus — sibling extension selectors that, like :animated, work inside jQuery but not in native querySelectorAll.