How can I count the options with the disabled option selected and efficiently with jquery?
How can I count the options with the disabled option selected and efficiently with jquery?
You do not need jQuery for this. You can do it with JavaScript and CSS selector :disabled
const nrA = document.querySelectorAll('option:disabled').length;
console.log('A', nrA);
const nrB = $('option:disabled').length;
console.log('B', nrB);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><select><optionvalue="Apple">Apple</option>
<option value="Banana" disabled>Banana</option>
<option value="Orange" disabled>Orange</option>
<option value="Grape">Grape</option>
</select>
A simple way to count using jQuery:
conta = $('select option:disabled').length;
console.log(conta);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><select><optionvalue="1" disabled="disabled">A</option>
<option value="2" disabled="disabled">B</option>
<option value="3">C</option>
<option value="4" disabled="disabled">D</option>
</select>