Sai Avinash
Sai Avinash

Reputation: 4753

How to disable a drop down list item in dropdown list on load using jquery

I have dropdown list with some list items . Here , i need to disable a single item in the dropdown list .

I mean value should be present in dropdown list but should not be selectable.

I have tried in the following way with no luck:

 $("#SelectorList select option [value*='n/a']").prop('disabled',true);

But, it is not working.i was able to disable entire dropdown list by using

 $("#SelectorList").prop('disabled',true);

What is the change that i need to do inorder to make this work. please help.

Upvotes: 0

Views: 13028

Answers (2)

Typo remove space

$("#SelectorList option[value*='n/a']").prop('disabled',true);
                       ^ //remove space here

fiddle Demo

Upvotes: 3

Adil
Adil

Reputation: 148120

Assuming SelectorList is id of select you can use combination of desandant selector and attribute value selector with contains wild card.

$("#SelectorList option[value*='n/a']").prop('disabled',true);

Upvotes: 11

Related Questions