0

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.

1
  • have your tried attr method instead prop? Commented Nov 20, 2013 at 10:24

2 Answers 2

11

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);
Sign up to request clarification or add additional context in comments.

3 Comments

@Adil..Thanks ..its working fine..Any idea how to do it, if it is inside Jqgrid..
I think it will work as you are using id for select. If you have multiple selects in grid then you can use class selector or assign ids in some pattern and make selector accordingly
You can put it in document.ready or after that, when SelectorList is present in DOM
3

Typo remove space

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

fiddle Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.