jQuery stop() Method (original) (raw)

Last Updated : 18 Nov, 2022

The stop() method is an inbuilt method in jQuery which is used to stop the currently running animations for the selected element.

Syntax:

$(selector).stop(stopAll, goToEnd);

Parameters: This method accepts two parameters as mentioned above and described below:

Below examples illustrate the stop() method in jQuery:
Example 1: This example does not contains any parameter.

HTML `

The stop Method
<!-- jQuery code to show the working of this method -->
<script>
    $(document).ready(function () {
        $("#gfg_start").click(function () {
            $("div").animate({
                height: 300
            }, 1000);
            $("div").animate({
                width: 300
            }, 1000);
        });
        $("#gfg_stop").click(function () {
            $("div").stop();
        });
    });
</script>
<style>
    div {
        background: green;
        height: 60px;
        width: 60px;
    }

    button {
        margin-bottom: 30px;
    }
</style>
Start Stop

`

Output:

Example 2: This example contains parameter.

HTML `

The stop Method
<script>
    $(document).ready(function () {
        var div = $("div");
        $("#start").click(function () {
            div.animate({
                height: 280
            }, "slow");
            div.animate({
                width: 280
            }, "slow");
            div.animate({
                height: 120
            }, "slow");
            div.animate({
                width: 120
            }, "slow");
        });
        $("#stop").click(function () {
            div.stop(true, true);
        });
    });
</script>
<style>
    div {
        background: green;
        height: 100px;
        width: 100px;
    }

    button {
        margin-bottom: 30px;
    }
</style>
Start Stop

`

Output: