How can I show and hide an HTML element using jQuery?


To hide and show an HTML element using jQuery, use the hide and show() methods. Here, the <p> element is hidden and shown on button click,

Example

Live Demo

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#visible").click(function(){
        $("p").show();
    });
     $("#hidden").click(function(){
        $("p").hide();
    });
});
</script>
</head>
<body>

<p>This text  will show on clicking "Show element" button, and hide on clicking "Hide element" button.</p>

<button id="hidden">Hide element</button>
<button id="visible">Show element</button>

</body>
</html>

Updated on: 15-Jun-2020

965 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements