Skip to content

Instantly share code, notes, and snippets.

@nmoliveira
Created July 26, 2013 10:09
Show Gist options
  • Save nmoliveira/6087782 to your computer and use it in GitHub Desktop.
Save nmoliveira/6087782 to your computer and use it in GitHub Desktop.
Adding options to an html select using Jquery
// array with values to be added
selectValues = { "1": "test 1", "2": "test 2" };
// for each value in the array append option to select
$.each(selectValues, function(key, value) {
$('#mySelect')
.append($('<option>', { value : key })
.text(value));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment