1

Using jQuery, I am trying to disable all non-selected items from multiple select elements except for one. I was trying to exclude the one select element based on its name attribute: name="tloStatus".

$(document).ready(function () { if($("select[name!=tloStatus]")) { $('option:not(:selected)').attr('disabled', true); } }); 

How do I only apply this:

$('option:not(:selected)').attr('disabled', true); 

to every select element but the one with name="tloStatus"?

1
  • Can you post the HTML too? Commented Mar 16, 2015 at 16:59

1 Answer 1

2

The reason it wasn't working was because you were selecting all unselected option elements regardless of the parent select element's name attribute.

You could simplify it to the following so that only unselected option elements that are a descendant are selected:

Example Here

$("select[name!=tloStatus] option:not(:selected)").attr('disabled', true); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.