Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Toggle CSS display of an Element</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <style> #myDiv{ padding: 20px; background: #abb1b8; margin-top: 10px; } </style> <script> $(document).ready(function(){ // Hide div by setting display to none $(".hide-btn").click(function(){ $("#myDiv").hide(); }); // Show div by removing inline display none style rule $(".show-btn").click(function(){ $("#myDiv").show(); }); // Toggle div display $(".toggle-btn").click(function(){ $("#myDiv").toggle(); }); }); </script> </head> <body> <button type="button" class="hide-btn">Hide</button> <button type="button" class="show-btn">Show</button> <button type="button" class="toggle-btn">Toggle</button> <div id="myDiv">#myDiv</div> </body> </html>