jQuery slideUp() example

jQuery slideDown() method is used to slide up an element.

Syntax

$(selector).slideUp(speed);  
$(selector).slideUp(speed, callback);   
$(selector).slideUp(speed, easing, callback);  
  • speed: It specifies the speed of the delay. Its possible values are slow, fast and milliseconds.
  • easing: It specifies the easing function to be used for transition.
  • callback: It is also an optional parameter. It specifies the function to be called after completion of slideUp() effect.

Example 1

<!DOCTYPE html>
<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#flip").click(function() {
                $("#panel").slideUp("slow");
            });
        });
    </script>
    <style>
        #panel,
        #flip {
            padding: 5px;
            text-align: center;
            background-color: #e5eecc;
            border: solid 1px #c3c3c3;
        }

        #panel {
            padding: 50px;
        }
    </style>
</head>

<body>

    <div id="flip">Click to slide up panel</div>
    <div id="panel">Hello world!</div>

</body>

</html>
Try it Yourself - Copy paste code in Online HTML Editor to see the result

Example 2

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>slideUp demo</title>
    <style>
        div {
            background: #3d9a44;
            margin: 3px;
            width: 80px;
            height: 40px;
            float: left;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>

<body>

    Click me!
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>

    <script>
        $(document.body).click(function() {
            if ($("div").first().is(":hidden")) {
                $("div").show("slow");
            } else {
                $("div").slideUp();
            }
        });
    </script>

</body>

</html>
Try it Yourself - Copy paste code in Online HTML Editor to see the result

Comments