<option> with display:none; does not work on IE
12,747
Solution 1
this seems to work for me:
$('select option').each(function(){
if(this.style.display == 'none')
{
$(this).remove();
}
});
Solution 2
John Boker's solution is the right one for this question. But it does have the downside that you won't be able to ever retrieve those options once you've removed them.
One solution is to save the full HTML of the <select>
before you remove any <option>
tags.
var $s = $('select');
$s.data("originalHTML", $s.html());
Now you can easily restore by reversing this: $s.html($s.data("originalHTML"));
Full details are on this solution: https://stackoverflow.com/a/24439289/1766230
Also an example: http://jsfiddle.net/luken/9CYjy/
Author by
user1246800
Updated on August 08, 2022Comments
-
user1246800 almost 2 years
I have some
style='display:none'
in the option element, it work well on Chrome and I realise it does not work on IE.<select> <option style="display:none;">One</option> <option>Two</option> <option style="display:none;">Three</option> <option>Four</option> </select>
Using jQuery, how to loop through the option to find
display:none
and remove the elements<option>
? -
alireza over 8 yearsremove ?? And how retrieve those options once you've removed them?!!! hide not work ! then remove it ?!
-
gabac over 7 yearsWhy the downvotes? The question asks how to remove the options, not hide them.