How to disable / enable jquery button

how to disable / activate a specific button using jquery (by name)?

The button has no identifier, only this code:

<button onclick="$('ChangeAction').value='SaveAndDoOrder';" value="Bye" name="SaveAndDoOrder" type="submit">
        <i class="Icon ContinueIconTiny"></i>
        <span class="SelectedItem">Bye</span>
      </button>
+5
source share
7 answers

I would recommend using an ID instead of a name, for example:

$("#myButton").attr("disabled", true);

This will add disabledan attribute to the button, which your browser will automatically disable. If you want to use the name, you can use it as follows:

$("button[name=myButton]").attr("disabled", true);
+5
source

Try the following:

$("button[name=SaveAndDoOrder]").attr("disabled", "disabled");

This will disable the button with an attribute nameequal to nameOfButton.

$("button[name=SaveAndDoOrder]").removeAttr("disabled");

This will remove the disable attribute from the same button.

+4
source

, .

, , name. name .

CSS Javascript DOM . , , , - , .

( IE, , [] CSS).

0

, :

function handleControlDisplay(className, foundCount, checked) {



    var button = jQuery(className);



    if (foundCount > 0 && foundCount == checked) {

        // enable

        button.removeAttr("disabled");

    }

    else {

        // set the disabled attribute

        button.attr("disabled", "true");

    };

}
0

jQuery:

; (function($) {
    $.fn.enable = function(b) {
        return this.each(function() {
            this.disabled = !b;
        });
    };
})(jQuery);

$(selector).enable(true|false);
0

, :

 <asp:Button runat="server" ID="btn1" Text="button!"/> 

:

$(document).ready  (function () {
    var a = $('#btn1');
    a.attr("disabled", function () {
        return "disabled";
    });     
}); 

0

I am using jQuery prop () :

$('#generate').click(function() {
    $(this).prop('disabled', true);
}

To enable the button again, do:

$(this).prop('disabled', false);

somewhere in your code.

0
source

All Articles