jQuery Selectors: Selecting an animated object

This entry is part 33 of 33 in the series jQuery Selectors

For jQuery, it is possible to select an animated object.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>animated demo</title>
    <style>
        div {
            background: yellow;
            border: 1px solid #AAA;
            width: 80px;
            height: 80px;
            margin: 0 5px;
            float: left;
        }

        div.colored {
            background: green;
        }
    </style>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
</head>
<body>

<button id='run'>Run</button>

<div></div>
<div id='mover'></div>
<div></div>

<script>
    $('#run').click(function () {
        $('div:animated').toggleClass('colored');
    });

    function animateIt() {
        $('#mover').slideToggle('slow', animateIt);
    }

    animateIt();
</script>

</body>
</html>
Series Navigation<< jQuery Selectors: The greater then gt selector

Leave a comment

Leave a Reply