Home » Javascript

jQuery - Disable Button After Click using jQuery

In this code snippet we will learn how to disable button after click using jQuery. With the help of this method we can prevent button to click after submitting form etc.

jQuery Code Snippet - Disable Button after Click using jQuery

jQuery/JavaScript

<script type="text/javascript">
	$(document).ready(function(){
		$("#btnSubmit").click(function(){
			$("#btnSubmit").prop('disabled',true);
		});
	});
	<!--JS function to display alert message-->
	function dispAlert(){
		alert("Button disabled.");
	}
</script>

HTML Source Code with jQuery/JavaScript

<!--jQuery - Disable Button After Click using jQuery.-->
<html>
	<head>
		<title>jQuery - Disable Button After Click using jQuery.</title>
		<!--Example CSS-->
		<link href="ExampleStyle.css" type="text/css" rel="stylesheet"/>
		<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
		
		<script type="text/javascript">
			$(document).ready(function(){
				$("#btnSubmit").click(function(){
					$("#btnSubmit").prop('disabled',true);
				});
			});
			<!--JS function to display alert message-->
			function dispAlert(){
				alert("Button disabled.");
			}
		</script>
	</head>
	<body>
		<h1>jQuery - Disable Button After Click using jQuery.</h1>
		<p><input type="button" value="Submit" id="btnSubmit" onclick='dispAlert()'/></p>
	</body>
</html>

Result

disable button after click





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.