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

jQueryWeb DevelopmentFront End Technology

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>
raja
Published on 22-Dec-2017 16:00:49
Advertisements