Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Options with display:none not hidden in IE

I have multiple options in a select. I have sorted the options and disabled and hidden the duplicate options with jquery. The code works well in chrome and firefox but in IE and safari, the options with display:none are still showing up.

Here is the jsfiddle of the code:

<select>
  <option value="5797">34</option>
  <option value="5809">37</option>
  ... 
  <option value="5653">71</option>
  <option disabled="" selected="selected" value="53">Eye</option>
  <option disabled="disabled" style="display: none;" value="5441">52</option>
  <option disabled="disabled" style="display: none;" value="5443">52</option>
  ...
  <option disabled="disabled" style="display: none;" value="5431">51</option>
</select>

http://jsfiddle.net/7vUdb/

like image 998
MJQ Avatar asked Dec 04 '13 11:12

MJQ


3 Answers

IE doesn't support style="display:none;" on <option> tags.

Your only option is to remove them - either as part of the creation of the HTML, or via client-side script.

like image 117
freefaller Avatar answered Nov 16 '22 11:11

freefaller


If somebody still faces this issue, here is my solution, it may be helpfull:

$('select.some-list option[id=someId]').attr('disabled', 'disabled').hide();

This hides the option in all browsers and disables if can't hide :). To bring back the option do not forget to enable it:

$('select.some-list option[id=someId]').removeAttr('disabled').show();
like image 21
Gev Avatar answered Nov 16 '22 11:11

Gev


You can use detach() and remove() to do this.

like image 4
Zhangjiang Huang Avatar answered Nov 16 '22 11:11

Zhangjiang Huang