2

I am trying to get rid of an empty option at the top of my select. This solution works in Chrome but not in IE as IE doesn't support display:none on options.

<option value="" style="display:none"></option> 

What would be the best way to hide it? I'm using AngularJS framework and tried plenty of solutions like ng-if but none of them work...

9
  • stackoverflow.com/questions/20373558/… Commented Aug 6, 2018 at 10:09
  • Your solution will not work in IE. If you are using AngularJS anyway, what about just editing the DOM and removing the <option>? If you need the <option> in another context, you can dynamically add/remove it. Commented Aug 6, 2018 at 10:11
  • I have seen that topic and I can't see how any of the answers is actually a reasonable choice. PS: I am not using jQuery. Commented Aug 6, 2018 at 10:13
  • If you have a reference to the select element, then select.removeChild(select.options[0]) will do the job. Commented Aug 6, 2018 at 10:13
  • 2
    Instead of fix in the wrong way, you shouldn't populate the empty options in the select element... Commented Aug 6, 2018 at 10:30

1 Answer 1

0

Okay, I've eventually came up with this solution. Isn't the prettiest but is a spot on fix for me

<option ng-if="false" value=""></option> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.