Adam Levitt
Adam Levitt

Reputation: 10476

jQuery find() select option not working in IE9

The following code works perfectly in non-IE browsers.

<select id="mySelect" name="mySelect">
  <option value="1">MyVal1</option>
  <option value="2">MyVal2</option>
  <option value="3">MyVal3</option>
</select>

I'm trying to clear out the options so I can add new ones:

var mySelect = $("#mySelect");
mySelect.find("option").remove();

It works the first time I try to populate it, but then every subsequent time thereafter, it ignores me.

Upvotes: 1

Views: 598

Answers (1)

Mark Pieszak - Trilon.io
Mark Pieszak - Trilon.io

Reputation: 66971

For removing options from a select, use .empty(). Works better, cross-browser wise.

mySelect.empty();

jsFiddle DEMO

Upvotes: 1

Related Questions