Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide select option in IE using jQuery

Currently I am using jQuery to hide/show select options using following code.

$("#custcol7 option[value=" + sizeValue + "]").hide(); 

This works fine in Firefox, but doesnt do any good in other browsers. How to I hide options from select in Chrome, Opera and IE?

like image 342
ITRushn Avatar asked Jan 09 '10 00:01

ITRushn


People also ask

How do I hide options in Internet Explorer selection?

The following jQuery will work in Internet Explorer, Firefox and Goolge Chrome (as well as other browsers). it will hide and disable the option: $('select option[value=saab]'). attr('disabled', 'disabled').

How to hide selected option from dropdown in jQuery?

Try this: $("#edit-field-service-sub-cat-value option[value=" + title + "]"). hide();

How to hide select box in jQuery?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none.


1 Answers

I just came across this and instead of cloning the entire select over and over I just replaced the options that need to be hidden with span elements and hiding the spans ( though the browser didnt visually show them anyway, I think ) - you may need to change your code ( if complex ) to iterate through the spans for complex logic.

The spans store a reference to the option and replace themselves with it when they need to be shown.

This code can obviously be refactored and prettified.

http://fiddle.jshell.net/FAkEK/12/show/

EDIT #2 ( USE THIS INSTEAD ): It occurred to me that instead of doing all this clone/reference/replace crap, just wrap the option with a span, hide the span, and on show just replace the span with the option again..

http://fiddle.jshell.net/FAkEK/25/show/

like image 174
meder omuraliev Avatar answered Sep 18 '22 23:09

meder omuraliev