jQuery fadeToggle() Method (original) (raw)

Last Updated : 23 Jul, 2024

The **fadeToggle() Method in **jQuery toggles between the fadeIn() and fadeOut() methods. If elements are faded in, fadeToggle() will fade out. If elements are faded out, fadeToggle() will fade in.

**Syntax:

$(selector).fadeToggle(speed, easing, callback)

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

Below examples illustrate the fadeToggle() method in jQuery:

**Example 1: This example display the fadeToggle() method effect in given speed. The speed can be set in terms of milliseconds.

HTML `

jQuery fadeToggle() Method
<style>
    #Outer {
        border: 1px solid black;
        padding-top: 40px;
        height: 140px;
        background: green;
        display: none;
    }
</style>

<script src=

"" title="undefined" rel="noopener noreferrer">https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">

<div id="Outer">
    <h1 style="color:white;">
        GeeksForGeeks
    </h1>
</div><br>

<button id="btn">
    Fade Toggle
</button>

<!-- Script to use fadeToggle() Method -->
<script>
    $(document).ready(function () {
        $("#btn").click(function () {
            $("#Outer").fadeToggle(1000);
        });
    });
</script>

`

**Output:

**Example 2: This example display the fadeToggle() method effect with swing easing. The easing is used to set the speed of element in different points of the animation.

HTML `

jQuery fadeToggle() Method
<style>
    #Outer {
        border: 1px solid black;
        padding-top: 40px;
        height: 140px;
        background: green;
        display: none;
    }
</style>

<script src=

"" title="undefined" rel="noopener noreferrer">https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">

<div id="Outer">
    <h1 style="color:white;">
        GeeksForGeeks
    </h1>
</div><br>

<button id="btn">
    Fade Toggle
</button>

<script>
    $(document).ready(function () {
        $("#btn").click(function () {
            $("#Outer").fadeToggle("swing");
        });
    });
</script>

`

**Output: