Skip to content Skip to sidebar Skip to footer

Temporarily Disable Button Using JQuery

I would like to disable a button element without removing the listener, for example I have ths following code:

Solution 1:

How about disabling the button instead of adding a class?

HTML:

<button>Disable Me</button>

JS

$(function() {
    $("button").click(function() {
        alert("click!");
       $(this).prop("disabled", true); 
    });
});

CSS

button[disabled] {
 color: red;
}

Here is a jsFiddle to demonstrate.


Solution 2:

use $('#sub').prop('disabled');


Post a Comment for "Temporarily Disable Button Using JQuery"