Home » Javascript

jQuery - Show/Hide Div on Button Click using jQuery

In this code example we will learn how to show/hide Div using jQuery - toggle() function. We will show and hide div on button click.

jQuery Code Snippet - Show/Hide Div on Button Click

jQuery/JavaScript

<!--jQuery to show/hide div-->
<script type="text/javascript">
	$(document).ready(function(){
		$("#btnShowHide").click(function(){
			$("#divShowHide").toggle();
		});
	});
</script>

HTML Source Code with jQuery/JavaScript

<!--jQuery - Show/Hide Div on Button Click using jQuery.-->
<html>
	<head>
		<title>jQuery - Show/Hide Div on Button Click using jQuery.</title>
		<!--Example CSS-->
		<link href="ExampleStyle.css" type="text/css" rel="stylesheet"/>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
		<!--jQuery to show/hide div-->
		<script type="text/javascript">
			$(document).ready(function(){
				$("#btnShowHide").click(function(){
					$("#divShowHide").toggle();
				});
			});
		</script>
	</head>
	<body>
		<h1>jQuery - Show/Hide Div on Button Click using jQuery.</h1>
		<p><input type="button" value="Show/Hide" id="btnShowHide"/></p>
		<div id="divShowHide" style="background-color: #fff; width: 100px; height: 100px;">
			Welcome to IncludeHelp.
		</div>
	</body>
</html>

Result

show hide div using jquery



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.