How can i get the unselected items from dropdown using jQuery
+5
A:
$('select#xyz option:not(:selected)');
or
$('#mySelect option').not(':selected');
Moin Zaman
2010-09-07 12:37:51
`"select#xyz"` as a selector is actually slower than `"#xyz"`. The latter looks into `document.getElementbyId()`, which is easily the fastest way of selecting.
James Wiseman
2010-09-07 12:39:47
@James is correct...also I can't think of an instance where this would be an efficient way to solve the problem :)
Nick Craver
2010-09-07 12:43:59
I wanted to show clearly that I was selecting a select.
Moin Zaman
2010-09-07 12:48:36
@Nick: efficient way to select unselected options in a dropdown? or are you referring to why select them in the first place as the questioner asked? if the former, then what's efficient?
Moin Zaman
2010-09-07 12:50:58
@Moin - Both :) `$("#xyz").val() != "something"` would typically be how to go about this, `#xyz` instead of `select#xyz` and `[selected]` would be the most efficient, but my point was more of selecting the options in the first place, a bad approach by the OP I imagine, but maybe there's some wacky valid reason for this I can't imagine....
Nick Craver
2010-09-07 12:55:05