Skip to content

Instantly share code, notes, and snippets.

@sineld
Forked from paulund/add-option-to-dropdown.js
Created October 16, 2018 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sineld/6b84a67b03144d04a86b7f39045f60d9 to your computer and use it in GitHub Desktop.
Save sineld/6b84a67b03144d04a86b7f39045f60d9 to your computer and use it in GitHub Desktop.
Add and Remove Options in Select using jQuery
$("#selectBox").append('<option value="option6">option6</option>');
$.each(selectValues, function(key, value) {
$('#mySelect')
.append($("<option></option>")
.attr("value",key)
.text(value));
});
<select id="selectBox" name="selectBox">
<option value="option1"> option1 </option>
<option value="option2"> option2 </option>
<option value="option3"> option3 </option>
<option value="option4"> option4 </option>
</select>
$('select').children('option:not(:first)').remove();
$("#selectBox option[value='option1']").remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment