Learn how you can disable buttons and prevent clicks with JavaScript
When you need to disable buttons using JavaScript, you can update the disabled
attribute of <button>
elements to true
.
Every HTML <button>
element has the disabled
attribute which is set to false
by default, even when the <button>
doesn’t have a disabled
attribute present. You can test this by running the following HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JavaScript disable button</title>
</head>
<body>
<button id="testBtn">Click me</button>
<script>
console.log(document.getElementById("testBtn").disabled); // false
</script>
</body>
</html>
#javascript #programming