Home »
JavaScript Examples
JavaScript - Disable Button after Click using JavaScript Function
In this code snippet we will learn how to disable a button on click event. In this example there will be button and it will be disabled after click on the button.
Function to Disable Button on Click
JavaScript function:
<script type="text/javascript">
function disableButton(btn) {
document.getElementById(btn.id).disabled = true;
alert("Button has been disabled.");
}
</script>
JavaScript and HTML Code to Disable Button after Click
<!--JavaScript - Disable Button after Click using JavaScript Function.-->
<html>
<head>
<title>JavaScript - Disable Button after Click using JavaScript Function.</title>
<script type="text/javascript">
function disableButton(btn) {
document.getElementById(btn.id).disabled = true;
alert("Button has been disabled.");
}
</script>
</head>
<body style="text-align: center;">
<h1>JavaScript - Disable Button after Click using JavaScript Function.</h1>
<p><input type="button" id="btn1" value="Click to disable button." onclick="disableButton(this)"</p>
</body>
</html>
Result:
JavaScript Examples »