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

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.