user1542984
user1542984

Reputation:

how to get status of disable and enable button in jQuery?

Can you please tell me how to get the status of disable and enable buttons in jQuery. I make disable and enable function, but I need to know how to get the status of the enable and disable button.

function disableButtons(){
    $('#saveButtonID').attr('src', 'Export-Realtime_disable.png');
    $('#searchID').attr('src', 'search_disable.png');
    $('#emailID').attr('src', 'Email-Document_disable.png');
    $('#saveButtonID').attr('disabled', 'disabled');
     $('#searchID').attr('disabled', 'disabled');
     $('#emailID').attr('disabled', 'disabled');

}

function enableButtons(){
    $('#saveButtonID').attr('src', 'Export-Realtime.png');
    $('#searchID').attr('src', 'search.png');
    $('#emailID').attr('src', 'Email-Document.png');
    $('#saveButtonID').removeAttr('disabled', 'disabled');
    $('#searchID').removeAttr('disabled', 'disabled');
    $('#emailID').removeAttr('disabled', 'disabled');


}

How would I get the status of the given button, is it disabled or enabled?

alert(''+ $('#searchID').attr('disabled'))

Upvotes: 0

Views: 9825

Answers (5)

atrichkov
atrichkov

Reputation: 477

Neither from answers above work for my button with disabled attribute, that's why I do this check:

$('#myBtnId').attr('disabled') === 'undefined') {...}

Upvotes: 1

Suraj Singh
Suraj Singh

Reputation: 4069

Use .is() operator to check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.

HERE

var chek = $("#searchID").is(":disabled")
alert(chek);

JsFiddle

Upvotes: 0

Mir Gulam Sarwar
Mir Gulam Sarwar

Reputation: 2648

Below will return true or false

$('#searchID').is(':disabled');

Upvotes: 4

Sridhar R
Sridhar R

Reputation: 20418

Try this

$("#searchID").is(":disabled")

OR

$('#searchID').prop('disabled')

DEMO

Upvotes: 2

Ankur Aggarwal
Ankur Aggarwal

Reputation: 3101

You can use

$("#searchId").is(":disabled")

Upvotes: 1

Related Questions