button klick, butto disabled in javascript

To handle clicking event and disabling a button in Javascript, you can use the following code:

<button id="myButton" onclick="handleClick()">Click me!</button>
65 chars
2 lines
function handleClick() {
  var myButton = document.getElementById("myButton");
  myButton.disabled = true;
}
109 chars
5 lines

In the above code, we first get a reference to the button element using its id attribute. Then, in the handleClick function, we set the disabled property of the button to true. This disables the button, preventing further clicks from triggering the onclick event.

Hope that helps!

gistlibby LogSnag