Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://select2.org/programmatic-control/add-select-clear-items
- // Select2 Ajax Value Preselected/Selected Value Using jQuery/JavaScript
- var data = {
- id: 1,
- text: 'Barn owl'
- };
- var newOption = new Option(data.text, data.id, false, false);
- $('#mySelect2').append(newOption).trigger('change');
- Multiple Select First Options
- $('#addForm select').each(function() {
- $(this).prop('selectedIndex', 0).trigger('change');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement