How do you remove all the options of a select box and then add one option and select it with jQuery?

Using core jQuery, how do you remove all the options of a select box, then add one option and select it?

My select box is the following.

<Select id="mySelect" size="9"> </Select>

EDIT: The following code was helpful with chaining. However, (in Internet¬†Explorer) .val('whatever') did not select the option that was added. (I did use the same ‘value’ in both .append and .val.)

.append('<option value="whatever">text</option>').val('whatever');

EDIT: Trying to get it to mimic this code, I use the following code whenever the page/form is reset. This select box is populated by a set of radio buttons. .focus() was closer, but the option did not appear selected like it does with .selected= "true". Nothing is wrong with my existing code – I am just trying to learn jQuery.

var mySelect = document.getElementById('mySelect');
mySelect.options.length = 0;
mySelect.options[0] = new Option ("Foo (only choice)", "Foo");

EDIT: selected answer was close to what I needed. This worked for me:

.append('<option selected value="whatever">text</option>') ;

But both answers led me to my final solution..

    .append('<option value="whatever">text</option>')

    .append('<option selected="selected" value="whatever">text</option>')

why not just use plain javascript?

document.getElementById("selectID").options.length = 0;

If your goal is to remove all the options from the select except the first one (typically the ‘Please pick an item’ option) you could use:


I had a bug in IE7 (works fine in IE6) where using the above jQuery methods would clear the select in the DOM but not on screen. Using the IE Developer Toolbar I could confirm that the select had been cleared and had the new items, but visually the select still showed the old items – even though you could not select them.

The fix was to use standard DOM methods/properites (as the poster original had) to clear rather than jQuery – still using jQuery to add options.

$('#mySelect')[0].options.length = 0;

Not sure exactly what you mean by “add one and select it”, since it will be selected by default anyway. But, if you were to add more than one, it would make more sense. How about something like:

$('select').append('<option id="foo">foo</option>');

Response to “EDIT”: Can you clarify what you mean by “This select box is populated by a set of radio buttons”? A <select> element cannot (legally) contain <input type="radio"> elements.

    .append('<option value="whatever">text</option>')

$("#control").html("<option selected="selected">The Option...</option>");

Just one line to remove all options from the select tag and after you can add any options then make second line to add options.


$('.ddlsl').append(new Option('Select all', 'all'));

One more short way but didn’t tried

$('.ddlsl').empty().append(new Option('Select all', 'all'));

Thanks to the answers I received, I was able to create something like the following, which suits my needs. My question was somewhat ambiguous. Thanks for following up. My final problem was solved by including “selected” in the option that I wanted selected.

$(function() {
  $('#mySelect').children().remove().end().append('<option selected value="One">One option</option>') ; // clear the select box, then add one option which is selected
  $("input[name="myRadio"]").filter( "[value="1"]" ).attr( "checked", "checked" ); // select radio button with value 1
  // Bind click event to each radio button.
                                  function() {
    switch(this.value) {
      case "1":
        $('#mySelect').find('option').remove().end().append('<option selected value="One">One option</option>') ;
        break ;
      case "2":
        $('#mySelect').find('option').remove() ;
        var items = ["Item1", "Item2", "Item3"] ; // Set locally for demo
        var options="" ;
        for (var i = 0; i < items.length; i++) {
          if (i==0) {
            options += '<option selected value="' + items[i] + '">' + items[i] + '</option>';
          else {
            options += '<option value="' + items[i] + '">' + items[i] + '</option>';
        $('#mySelect').html(options);   // Populate select box with array
        break ;
    } // Switch end
  } // Bind function end
                                 ); // bind end
}); // Event listener end
<script src=""></script>
<label>One<input  name="myRadio" type="radio" value="1"  /></label>
<label>Two<input name="myRadio"  type="radio" value="2" /></label>
<select id="mySelect" size="9"></select>

I’ve found on the net something like below. With a thousands of options like in my situation this is a lot faster than .empty() or .find().remove() from jQuery.

var ClearOptionsFast = function(id) {
    var selectObj = document.getElementById(id);
    var selectParentNode = selectObj.parentNode;
    var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
    selectParentNode.replaceChild(newSelectObj, selectObj);
    return newSelectObj;

More info here.

How about just changing the html to new data.

$('#mySelect').html('<option value="whatever">text</option>');

Another example:

    <option value="1" selected>text1</option>
    <option value="2">text2</option>
    <option value="3" disabled>text3</option>

Another way:


Under this link, there are good practices

  1. First clear all exisiting option execpt the first one(–Select–)

  2. Append new option values using loop one by one

    for (var i = 0; i < oResult.length; i++) {
       $("#ddlCustomer").append(new Option(oResult[i].CustomerName, oResult[i].CustomerID + "" + oResult[i].ID));
$("#id option").remove();
$("#id").append('<option value="testValue" >TestText</option>');

The first line of code will remove all the options of a select box as no option find criteria has been mentioned.

The second line of code will add the Option with the specified value(“testValue”) and Text(“TestText”).

Building on mauretto’s answer, this is a little easier to read and understand:


To remove all the options except one with a specific value, you can use this:


This would be better if the option to be added was already there.

Uses the jquery prop() to clear the selected option

$('#mySelect option:selected').prop('selected', false);

This will replace your existing mySelect with a new mySelect.

$('#mySelect').replaceWith('<Select id="mySelect" size="9">
   <option value="whatever" selected="selected" >text</option>

You can do simply by replacing html

.html('<option value="whatever" selected>text</option>')

  • save the option values to be appended in an object
  • clear existing options in the select tag
  • iterate the list object and append the contents to the intended select tag
var listToAppend = {'':'Select Vehicle','mc': 'Motor Cyle', 'tr': 'Tricycle'};


$.each(listToAppend, function(val, text) {
    $('#selectID').append( new Option(text,val) );
<script src=""></script>

I saw this code in Select2 –
Clearing Selections


This code works well with jQuery even without Select2

Hope it will work


I used vanilla javascript

let select = document.getElementById("mySelect");
select.innerHTML = "";

var select = $('#mySelect');
var data = [{"id":1,"title":"Option one"}, {"id":2,"title":"Option two"}];
for(var i in data) {
    var d = data[i];
    var option = $('<option/>').val(;


mySelect.innerHTML = `<option selected value="whatever">text</option>`

function setOne() {
  mySelect.innerHTML = `<option selected value="whatever">text</option>`;
<button onclick="setOne()" >set one</button>
<Select id="mySelect" size="9"> 
 <option value="1">old1</option>
 <option value="2">old2</option>
 <option value="3">old3</option>

The shortest answer:

$('#mySelect option').remove().append('<option selected value="whatever">text</option>');

Leave a Comment