If you want to achieve this using pure vanilla JavaScript, it's quite simple:
const button = document.getElementById("myButton");
button.onclick = function() {
button.disabled = true; // disable the button
setTimeout(function() {
button.disabled = false; // enable the button after 2 seconds
}, 2000); // 2 seconds
}; // Please note that this will overwrite any existing onclick event
Alternatively, if you are using jQuery, you can use the following code:
const button = $("#myButton");
button.click(function() {
button.attr("disabled", "disabled"); // disable the button
setTimeout(function() {
button.removeAttr("disabled"); // enable the button after 2 seconds
}, 2000); // 2 seconds
});