Reputation:
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
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
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.
var chek = $("#searchID").is(":disabled")
alert(chek);
Upvotes: 0
Reputation: 2648
Below will return true or false
$('#searchID').is(':disabled');
Upvotes: 4
Reputation: 20418
Try this
$("#searchID").is(":disabled")
OR
$('#searchID').prop('disabled')
Upvotes: 2