jQuery show() examples

The jQuery show() method is used to show the selected elements.

Syntax

$(selector).show();  
$(selector).show(speed, callback);  
$(selector).show(speed, easing, callback);  
  • speed: It is an optional parameter. 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 the show() 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() {
            $("#hide").click(function() {
                $("p").hide();
            });
            $("#show").click(function() {
                $("p").show();
            });
        });
    </script>
</head>

<body>

    <p> jQuery hide() method is used to hide the selected elements.</p>
    <p>jQuery show() method is used to show the selected elements.</p>
    <button id="hide">Hide</button>
    <button id="show">Show</button>

</body>

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

Example 2

Animates all hidden paragraphs to show slowly, completing the animation within 600 milliseconds.
<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>show demo</title>
    <style>
        p {
            background: yellow;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>

<body>

    <button>Show it</button>
    <p style="display: none">Hello 2</p>

    <script>
        $("button").click(function() {
            $("p").show("slow");
        });
    </script>

</body>

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

References


Comments