jQuery -

Show

The jQuery .show() method is used to display the selected elements. This tutorial covers different aspects of using the .show() method with detailed explanations and examples.


1. Basic Show

You can use the .show() method to display an element.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Basic</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("p").show();
            });
        });
    </script>
</head>
<body>
    <p style="display:none;">This is a hidden paragraph.</p>
    <button id="showButton">Show Paragraph</button>
</body>
</html>
        
    

This example shows how to display a paragraph when a button is clicked using the .show() method.


2. Show with Duration

You can specify the duration for the show effect, making it a smooth transition.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Duration</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("div").show(1000);
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="showButton">Show Div with Duration</button>
</body>
</html>
        
    

This example demonstrates how to display a div with a specified duration.


3. Show with Callback

You can execute a callback function after the show effect is completed.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Callback</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("p").show("slow", function(){
                    alert("The paragraph is now visible.");
                });
            });
        });
    </script>
</head>
<body>
    <p style="display:none;">This is a hidden paragraph.</p>
    <button id="showButton">Show Paragraph with Callback</button>
</body>
</html>
        
    

This example shows how to execute a callback function after displaying an element.



4. Show with Easing

You can use different easing functions to change the show animation's acceleration.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Easing</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("div").show("slow", "easeOutBounce");
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="showButton">Show Div with Easing</button>
</body>
</html>
        
    

This example demonstrates how to use an easing function with the .show() method.


5. Show Multiple Elements

You can display multiple elements at once by selecting them using a common class or element type.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Multiple Elements</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $(".showable").show();
            });
        });
    </script>
</head>
<body>
    <p class="showable" style="display:none;">Paragraph 1</p>
    <p class="showable" style="display:none;">Paragraph 2</p>
    <p class="showable" style="display:none;">Paragraph 3</p>
    <button id="showButton">Show All Paragraphs</button>
</body>
</html>
        
    

This example shows how to display multiple paragraphs with a single button click.


6. Toggle Show and Hide

You can use the .toggle() method to toggle between hiding and showing elements.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .toggle() Method</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#toggleButton").click(function(){
                $("div").toggle();
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="toggleButton">Toggle Visibility</button>
</body>
</html>
        
    

This example demonstrates how to toggle the visibility of a div using the .toggle() method.



7. Show with CSS Display Property

The .show() method sets the CSS display property of the selected elements to their default display type.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - CSS Display Property</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("p").show();
                alert("CSS Display Property: " + $("p").css("display"));
            });
        });
    </script>
</head>
<body>
    <p style="display:none;">This is a hidden paragraph.</p>
    <button id="showButton">Show Paragraph</button>
</body>
</html>
        
    

This example shows the effect of the .show() method on the CSS display property of an element.


8. Show with Custom Animation

You can create custom show animations using the .animate() method.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .animate() Method - Custom Show Animation</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("div").animate({opacity: 1, height: "toggle"});
            });
        });
    </script>
</head>
<body>
    <div style="display:none; opacity: 0; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="showButton">Show with Custom Animation</button>
</body>
</html>
        
    

This example demonstrates how to create a custom show animation.


9. Show Parent Element

You can display a parent element and all its children using the .show() method.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Show Parent Element</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $(".parent").show();
            });
        });
    </script>
</head>
<body>
    <div class="parent" style="display:none; background-color: yellow; padding: 10px;">
        <p>This is a paragraph inside a div.</p>
        <span>This is a span inside the same div.</span>
    </div>
    <button id="showButton">Show Parent Element</button>
</body>
</html>
        
    

This example shows how to display a parent div and all its child elements.


10. Chaining Show with Other Methods

You can chain the .show() method with other jQuery methods for more complex animations and effects.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery Chaining Methods - .show()</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#chainButton").click(function(){
                $("p").css("color", "red").slideDown(1000).show(1000);
            });
        });
    </script>
</head>
<body>
    <p style="display:none;">This is a hidden paragraph.</p>
    <button id="chainButton">Chain Methods</button>
</body>
</html>
        
    

This example demonstrates how to chain the .show() method with other methods.



11. Show with Custom Speed

You can specify custom speeds for the show effect using predefined speeds or milliseconds.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method - Custom Speed</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("div").show(1500);
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="showButton">Show with Custom Speed</button>
</body>
</html>
        
    

This example shows how to display an element with a custom speed.


12. Show with Slide Effect

You can use the .slideDown() method to display elements with a slide-down effect.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .slideDown() Method</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#slideDownButton").click(function(){
                $("div").slideDown();
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="slideDownButton">Show with Slide Effect</button>
</body>
</html>
        
    

This example demonstrates how to display an element with a slide-down effect.


13. Show with Fade Effect

You can use the .fadeIn() method to display elements with a fade-in effect.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .fadeIn() Method</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#fadeInButton").click(function(){
                $("div").fadeIn();
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="fadeInButton">Show with Fade Effect</button>
</body>
</html>
        
    

This example shows how to display an element with a fade-in effect.


14. Show with Delay

You can delay the show effect using the .delay() method before displaying the element.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .delay() Method</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#delayButton").click(function(){
                $("div").delay(2000).show(1000);
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">This is a div element.</div>
    <button id="delayButton">Show with Delay</button>
</body>
</html>
        
    

This example demonstrates how to delay the show effect before displaying an element.


15. Show on Hover

You can display elements when a user hovers over them using the .hover() method.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .hover() Method</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("div").hover(function(){
                $(this).show();
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">Hover over this div to show it.</div>
</body>
</html>
        
    

This example shows how to display an element when the user hovers over it.


16. Show with Keyboard Event

You can display elements in response to keyboard events such as pressing a specific key.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery Keyboard Event - .show()</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $(document).keypress(function(e){
                if(e.which == 13) { // Enter key
                    $("div").show();
                }
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">Press Enter to show this div.</div>
</body>
</html>
        
    

This example demonstrates how to display an element when a specific key is pressed.


17. Show with Mouse Event

You can display elements in response to mouse events such as clicking or double-clicking.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery Mouse Event - .show()</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("div").click(function(){
                $(this).show();
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">Click on this div to show it.</div>
</body>
</html>
        
    

This example shows how to display an element when the user clicks on it.


18. Show with Form Submission

You can display elements when a form is submitted.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery Form Submission - .show()</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("form").submit(function(event){
                event.preventDefault();
                $("div").show();
            });
        });
    </script>
</head>
<body>
    <form>
        <input type="text" placeholder="Type something">
        <button type="submit">Submit</button>
    </form>
    <div style="display:none; background-color: yellow; padding: 10px;">This div will be shown on form submission.</div>
</body>
</html>
        
    

This example demonstrates how to display an element when a form is submitted.


19. Show with Window Resize

You can display elements when the browser window is resized.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery Window Resize - .show()</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $(window).resize(function(){
                $("div").show();
            });
        });
    </script>
</head>
<body>
    <div style="display:none; background-color: yellow; padding: 10px;">Resize the window to show this div.</div>
</body>
</html>
        
    

This example shows how to display an element when the window is resized.


20. Restore Visibility

You can restore the visibility of hidden elements using the .hide() or .toggle() methods.

Try yourself
        
            <!DOCTYPE html>
<html>
<head>
    <title>jQuery .show() Method</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#showButton").click(function(){
                $("p").show();
            });
        });
    </script>
</head>
<body>
    <p style="display:none;">This is a hidden paragraph.</p>
    <button id="showButton">Show Paragraph</button>
</body>
</html>
        
    

This example demonstrates how to restore the visibility of hidden elements using the .hide() method.