How to make a Button Clickable only once in JavaScript?

To make a button clickable only once, just set it to disable or remove its existing onclick event on the first execution.

Example:

<button id="myButton" onclick="myFunction()">Click the button</button>

<script>
    function myFunction() {
        document.getElementById("myButton").disabled = true;
        console.log('hello');
    }
</script>

This will allow you to print only one “hello” in console, no matter how many times you’ll click the button (it’ll be disabled after the first click).