jQuery Effect fadeOut() Method (original) (raw)

Last Updated : 18 Nov, 2022

The fadeOut()Method in jQuery is used to change the level of opacity for selected element from visible to hidden. By using this method, the faded element will not occupy any space.

Syntax:

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

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

Example 1: This example display fadeIn and fadeOut effect.

HTML `

jQuery | fadeOut() Method
<h1 style="color:green;">
    GeeksForGeeks
</h1>
<h2>jQuery | fadeOut() Method</h2>
<button class="btn1">Fade out</button>
<button class="btn2">Fade in</button>

<!-- Script to display fadeIn and fadeOut effect -->
<script>
    $(document).ready(function () {
        $(".btn1").click(function () {
            $("h2").fadeOut()
        });

        $(".btn2").click(function () {
            $("h2").fadeIn();
        });
    });
</script>

`

Output:

Example 2: This example create fadeIn and fadeOut effect and set its speed. The given speed in terms of milliseconds.

HTML `

jQuery | fadeOut() Method

GeeksForGeeks

jQuery | fadeOut() Method

Fade out Fade in
<script>
    $(document).ready(function () {
        $(".btn1").click(function () {
            $("h2").fadeOut(1000);
        });

        $(".btn2").click(function () {
            $("h2").fadeIn(1000);
        });
    });
</script>

`

Output:

Example 3: Create fadeIn and fadeOut effect with alert message.

HTML `

jQuery | fadeOut() Method

GeeksForGeeks

jQuery | fadeOut() Method

Fade out Fade in
<!-- Script to create fadeIn and fadeOut effect -->
<script>
    $(document).ready(function () {
        $(".btn1").click(function () {
            $("h2").fadeOut(1000, function () {
                alert("fadeOut() method is finished!");
            });
        });

        $(".btn2").click(function () {
            $("h2").fadeIn(1000, function () {
                alert("fadeIn() method is finished!");
            });
        });
    });
</script>

`

Output: