Disable input type="button" (JavaScript)
How to disable input type="button" by means of JavaScript and setAttribute() method:
HTML code:
<div class="example">
<input type="button" value="button" />
</div>
JavaScript code:
<script>
var button = document.querySelector('input[type="button"]');
function disableButton() {
button.setAttribute('disabled', 'disabled');
}
button.addEventListener('click', disableButton);
</script>
Links
- Element: setAttribute() method: developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
Browser support
- Windows
- Edge 12.0+
- Firefox 3.5+
- Google Chrome 1.0+
- Opera 10.0+
- Linux
- Firefox 3.5+
- Google Chrome 1.0+
- Opera 10.0+
- iOS
- Safari 2.0+
- Android
- Samsung Internet 1.0+
- Chrome Android 18.0+
- Firefox for Android 4.0+
- Opera Android 10.1+