Uday kumar das Uday kumar das - 6 months ago 11
jQuery Question

find dropdown by attribute disabled false

I have same dropdown many times in my file like:

<select style="width:40%;" name="article[subsection_id]" id="article_subsection_id" class="article_subsection_cls" disabled="disabled"><option value=""></option>




I want to find dropdown by class
article_subsection_cls
or id
article_subsection_id
and attribute
disabled
is
false
.

Answer

Use attribute equals selector with :not() pseudo selector

$('select#article_subsection_id:not([disabled="disabled"]),select.article_subsection_cls:not([disabled="disabled"])')

If disabled property updated dynamically in that case use filter() method

$('select.article_subsection_cls,select#article_subsection_id').filter(function(){ return !this.disabled; })

UPDATE : In case there is only one element use id selector

$('#article_subsection_id:not([disabled="disabled"])')

Or you can use :enabled selector

Although their resulting selections are usually the same, :enabled selector is subtly different from :not([disabled]); :enabled selects elements that have their boolean disabled property strictly equal to false, while :not([disabled]) selects elements that do not have a disabled attribute set (regardless of its value).

$('#article_subsection_id:enabled')