Yunhee last month

jquery find disabled in select box

I have three select boxes.

 <select id="box1">   
 <option>foo1</option>   
 </select>               

 <select id="box2">
 <option>foo2</option>
 </select>

 <select id="box3">
 <option disabled>foo3</option>
 </select>

i need to get select id of option:disabled.-> (box3)

how to find id of option:disabled with jquery?

Answers


VadimB last month

You can use :disabled pseudo selector to achieve this

$('select option:disabled')

To get parent element - you can use closest selector or parent

console.log($('select option:disabled').closest('select').attr('id'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select id="box1">       
   <option disabled>foo1</option>
</select>

<select id="box2">       
   <option>foo1</option>
</select>


guradio last month

alert($('option:disabled').parent().attr('id'))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="box2">

</select>
<select id="box1">

</select>
<select id="box3">
  <option>foo1</option>
  <option>foo2
  </option>
  <option disabled>foo3</option>
</select>

Use selector :disabled

Post Status

Asked in last month
Viewed 1,232 times
Voted 4
Answered 2 times

Search




Leave an answer