I want to create a button that gets disabled after one click/is just clickable one time... I couldnt find anything about it.
Asked
Active
Viewed 161 times
-1
-
Hi can you kindly display your attempt at what have you have tried? – innocent Apr 23 '22 at 23:32
-
You can remove an event listener or use a boolean flag and an `if` and/or add the `disabled` property. Which you choose depends on your use case, particular needs and existing code, which hasn't been described or shared yet (please [edit] to add details!). – ggorlen Apr 23 '22 at 23:34
1 Answers
3
Add a click event listener to the button which disables it.
document.querySelector('button').addEventListener('click', function(){
this.disabled = true;
})
<button>Button</button>

Spectric
- 30,714
- 6
- 20
- 43