Click here to Skip to main content
15,844,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do I check if button element is disabled or enabled?

What I have tried:

html:
<pre lang="HTML"><button type='button' disabled> </button>


JS:
JavaScript
if($("#follow").disable){
    // do stuff
}
Posted
Updated 22-Dec-19 18:45pm

Using JQuery (which your What I have Tried example suggests you're using), there's the disabled property, which you can access as follows:
JavaScript
if ($('#follow').prop('disabled') {
  // do stuff
}
You can also use prop() to set the property, by passing true or false as a second parameter:
JavaScript
$('#follow').prop('disabled',true);
You will find lots of other properties too. See https://api.jquery.com/prop/[^] for more info.
 
Share this answer
 
jQuery also provides a :disabled selector which you can use to test:
JavaScript
if ($("#follow").is(":disabled")){
    // do stuff
}
.is() | jQuery API Documentation[^]
:disabled Selector | jQuery API Documentation[^]

But you don't necessarily need jQuery - you can do this quite simply in plain Javascript:
JavaScript
if (document.getElementById("follow").disabled){
    // do stuff
}
 
Share this answer
 
Hi
I have created a demo for it in below link. By this, you can check if button is disabled or not. please find below link:
Check button Enabled or Disabled[^]

Try this and let me know if you have any query.
Hope this will help you.
Thank you.
 
Share this answer
 
Hello check if element is disabled or enabled try this
<button type='button' id="btntest" disabled> </button>

if ($('#btntest').prop('disabled') {
  // do stuff
}
 
Share this answer
 
Comments
Maciej Los 23-Dec-19 2:29am    
My vote of 1!
This is the exact copy of solution 1 (even if there's different name of button).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900