remove all options from select jquery but only one

user1428798 picture user1428798 · Sep 18, 2013 · Viewed 54.7k times · Source

I have a select that contain this values:

<select id="lstCities" class="valid" name="City">
<option value="OSNY">OSNY</option>
<option value="dd">dd</option>
<option value="OSffNY">OSffNY</option>
<option value="ANTONY">ANTONY</option>
<option value="0">Autre...</option>
</select>

How can I delete all options but i would like to keep only

 <option value="0">Autre...</option>

My problem is my list is dynamic sometimes I have 3,5,7,.... select + the last one <option value="0">Autre...</option>

Answer

adeneo picture adeneo · Sep 18, 2013

select all options, then exclude the one with that value :

$('#lstCities option[value!="0"]').remove();

FIDDLE