This should work:
$('option').hide(); // hide options
It works in Firefox, but not Chrome (and probably not in IE, not tested).
A more interesting example:
<select>
<option class="hide">Hide me</option>
<option>visible option</option>
</select>
<script type="text/javascript">
// try to hide the first option
$('option.hide').hide();
// to select the first visible option
$('option:visible').first().attr('selected', 'selected');
</script>
Or see the example at http://jsfiddle.net/TGxUf/
Is the only option to detach the option elements from the DOM? I need to show them again later, so this would not be very effective.
It's possible if you keep in object and filter it in short way.
-
https://jsfiddle.net/2djv7zgv/4/
Had a crack at it myself and this is what I came up with:
You can see the example at http://www.jsfiddle.net/g5YKh/
The
option
elements are fully removed from theselect
s and can be re-added again by jQuery selector.Probably needs a bit of work and testing before it works well enough for all cases, but it's good enough for what I need.
This is an enhanced version of @NeverEndingLearner's answer:
just modify dave1010's code for my need
http://jsfiddle.net/AbzL3/1/
Hiding an
<option>
element is not in the spec. But you candisable
them, which should work cross-browser.http://www.w3.org/TR/html401/interact/forms.html#h-17.6
Try this:
But I think it doesn't make sense to hide it. if you wanna remove it, just: