I have an object with key/value pairs of options I want to hide/remove from a select list. Neither of the following option selectors work. What am I missing?
$.each(results['hide'], function(name, title) { $("#edit-field-service-sub-cat-value option[value=title]").hide(); $("#edit-field-service-sub-cat-value option[@value=title]").hide(); });
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <option> element is not visible, but it maintains its position on the page. Removing the hidden attribute makes it re-appear.
If you want to hide/show div on dropdown selected, use the jQuery hide() and show(). Before you perform hide or show div on dropdown selection, you need to hide them first using CSS display:none.
$(this). find('[value="X"]'). remove();
For what it's worth, the second form (with the @
) doesn't exist in jQuery 1.3. The first isn't working because you're apparently expecting variable interpolation. Try this:
$("#edit-field-service-sub-cat-value option[value=" + title + "]").hide();
Note that this will probably break in various hideous ways if title
contains jQuery selector metacharacters.
You cannot do this x-browser. If I recall ie has issues. The easiest thing to do is keep a cloned copy of the select before you remove items, this allows you to easily remove and then append the missing items back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With