Skip to content

Instantly share code, notes, and snippets.

@ansidev
Created April 15, 2017 04:34
Show Gist options
  • Save ansidev/1c2d1693f086e82cec5cf6bd075e3454 to your computer and use it in GitHub Desktop.
Save ansidev/1c2d1693f086e82cec5cf6bd075e3454 to your computer and use it in GitHub Desktop.
// JQuery tips for select
var selectElement = $('#select-id');
// Clear all select options
selectElement.empty();
// Append options to select
selectElement.append($('<option>', {
value: 'value',
text: 'text'
}));
// Append options from a collection of items
$.each(items, function (i, item) {
selectElement.append($('<option>', {
value: item.value,
text : item.text
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment