80 of 119 menu

Selector animated

The :animated selector selects elements that are currently being animated. If you are using a custom jQuery build without the effects module, using :animated will throw an error. Since :animated is not part of the CSS spec, for better performance in modern browsers it is better to first filter elements using a pure CSS selector, and then apply .filter(':animated').

Syntax

This is how we select the elements involved in the animation:

$(':animated');

Example

Let's make one of the squares to start an animation using the animateIt function. Each time the button with #change is clicked, the color of the animated square will change from green to red and back - by removing and adding the colored class using the toggleClass method:

<button id="change">change</button> <div></div> <div id="test"></div> div { background: green; border: 1px solid #AAA; width: 80px; height: 80px; margin: 0 5px; float: left; } div.colored { background: red; } $('#change').click(function() { $('div:animated').toggleClass('colored'); }); function animateIt() { $('#test').slideToggle('slow', animateIt); } animateIt();

See also

  • method slideToggle,
    which shows hidden elements and hides shown ones
  • method toggleClass,
    which adds or removes a CSS class
  • method find,
    which searches for elements within those already found
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline