Skip to content

Instantly share code, notes, and snippets.

@melvinstanly
Last active February 13, 2019 07:24
Show Gist options
  • Save melvinstanly/0c556ebcbb93071bcbc6fd675ee59f42 to your computer and use it in GitHub Desktop.
Save melvinstanly/0c556ebcbb93071bcbc6fd675ee59f42 to your computer and use it in GitHub Desktop.
jQuery select2
/* Dynamically add options to select field */
// Assuming 'custom-select' is the class of select field
<select class="custom-select">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
var mySelect = $(".custom-select").append('<option value="test">Test</option>');
mySelect.trigger("change");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment