115

I need to find if a textbox is disabled or enabled using Jquery.

5 Answers 5

179

.prop('disabled') will return a Boolean:

var isDisabled = $('textbox').prop('disabled');

Here's the fiddle: http://jsfiddle.net/unhjM/

3
  • For some reason this does not work on my application even though in the fiddle it works perfectly. When I run it firebug says .prop is not a function! Is it something related to the version of jquery? Anyways, .is(':disabled') seems to work fine. Thanks. Thanks. Commented Nov 25, 2012 at 9:01
  • 2
    @MohammedJoraid - .prop() was introduced in jQuery 1.6 (see the docs). If you're using an earlier version of jQuery, use .attr() instead. Commented Nov 25, 2012 at 18:44
  • @ChamanSaini you are misleading. The format $('input') is intended to select a "control of type" input, while $('#input') will match an element with the id "input" regardless of it's type.
    – TTomer
    Commented Aug 29, 2018 at 17:43
84

You can find if the textbox is disabled using is method by passing :disabled selector to it. Try this.

if($('textbox').is(':disabled')){
     //textbox is disabled
}
0
15

You can use $(":disabled") to select all disabled items in the current context.

To determine whether a single item is disabled you can use $("#textbox1").is(":disabled").

6

You can check if a element is disabled or not with this:

if($("#slcCausaRechazo").prop('disabled') == false)
{
//your code to realice 
}
2
  • 1
    With boolean comparison there is no need to test against true or false. Simply use if (expr) or if (! expr), respectively. Commented Oct 12, 2018 at 1:06
  • You are right if($("#slcCausaRechazo").prop('disabled') ) { //your code to realice if is disabled }
    – user4272288
    Commented Oct 13, 2018 at 16:00
6
 if($("element_selector").attr('disabled') || $("element_selector").prop('disabled'))
 {

    // code when element is disabled

  }

Not the answer you're looking for? Browse other questions tagged or ask your own question.