[jquery] How to check if dropdown is disabled?

Using jquery how do i simply check if it is read only?

this is what i am trying..

$("#item").keydown(function (event) {
     //alert(event.keyCode);
     if (event.keyCode == 13) {
         $("#ok").click();               
         if ($('#dropLength').prop("disabled") == false) {
             $("#dropLength").focus();
             return;
         }
         if ($('#dropUnit').prop("disabled") == false) {
             $("#dropUnit").focus();
             return;
         }
         $("#qty").focus();                
         return ;
     }
 });

The dropdowns are set to readonly using jquery also:

if ($('#dropLength').find('option').length <= 1) {
      $('#dropLength').attr("disabled", "disabled");
}
if ($('#dropUnit').find('option').length <= 1) {
      $('#dropUnit').attr("disabled", "disabled");
}   

This question is related to jquery

The answer is


There are two options:

First

You can also use like is()

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

Second

Using == true by checking if the attributes value is disabled. attr()

$('#dropDownId').attr('disabled');

whatever you feel fits better , you can use :)

Cheers!


Try following or check demo disabled and readonly

$('#dropUnit').is(':disabled') //Returns bool
$('#dropUnit').attr('readonly') == "readonly"  //If Condition

You can check jQuery FAQ .


I was searching for something like this, because I've got to check which of all my selects are disabled.

So I use this:

let select= $("select");

for (let i = 0; i < select.length; i++) {
    const element = select[i];
    if(element.disabled == true ){
        console.log(element)
    }
}