select2 add option

Remove the selected options : 
-----------------------------
$('#mySelect2').val(null).trigger('change');

============================================

Completly remove the select2 initialization :
--------------------------------------------
$('#payment_method').html('').select2({data: [{id: '', text: ''}]});

5
1
Josef7 85 points

                                    // Set the value, creating a new option if necessary
if ($('#mySelect2').find("option[value='" + data.id + "']").length) {
    $('#mySelect2').val(data.id).trigger('change');
} else { 
    // Create a DOM Option and pre-select by default
    var newOption = new Option(data.text, data.id, true, true);
    // Append it to the select
    $('#mySelect2').append(newOption).trigger('change');
} 

5 (1 Votes)
0
3.5
4

                                    $('#select2')
    .select2()
    .on('select2:open', () => {
        $(".select2-results:not(:has(a))").append('<a href="#" style="padding: 6px;height: 20px;display: inline-table;">Create new item</a>');
})

3.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
dynamically add options to select2 select2 clear the select select 2 clear all select 2 clear how add select2 dropdown dynamically select2 clear search fiedl after select select2 clear options allowclear select2 add option to dropwdown list select2 trigger new option on clear clear select2 selected value add select2 to a dynamic select select option select2 clear select2 and fill select clear options select2 clear options ajax how to add a selection to the same field select2 select2 dropdown add span in select select2 dropdown add option dynamically select2-selection__clear event select2 set option selected how to clear all selected value in select2 select2 add new item clear button select2 add select option dropdown in select2 add select option in select2 clear all options select 2 how to clear selected option in select2 select2 clear selected option select option dynamically select2 how to clear select2 selected items how to clear select2 data select2 clearable append to a dropdown select2 append option select2 add new option in select2 jquery select2 add option html add custom option in select2 add select2 select select2 option selected option select2 select2 trigger clear select2 select clear select2{'clear'} clear select2 not clear value add select2 dy clear true in select2 select2 add option and set selected clear value select2 how to add select2 to dropdown clear select2 every call select2 addoptions new option select2 get option select2 select2 select and append select2 option line how to insert options in select2 change select2 options select2 how to clear selection add value in select2 dropdown select2 multiple select clear clear selected select2 select2 Add, select, or clear items reset a select2 add option name select in select2 select 2 how to add new option select2 dropdown clear selection select2 destroy and clear select2 options add select2 on add more reset all select2 dynamically add option to select2 select2 event clear adding options to select2 how to remove allow clear in select2 clear select2 selection select 2 clear all options select2 allow clear add button to select2 dropdown add clear button select2 clear selected option select2 clear select2 use js select2 append option select2 append options select2 add option js append to dropdownParent in select2 select2-selection__clear hide select2-results__option clear select2 clear search dropdown clear select2.result.option select2 clear search input select2 get value before clear get value 'select2:clearing set selected option select2 select2 option value select2 clear selected item select2 on clear event Select2 Adding options select2 select an option select2 option allow clear select2 make option selected how to add new in select2 option select2 prepend option clear value in select2 clear select 2 select2 clear method on select2 clear items event clear select2 dropdown clear select2 list select2 add button to dropdown select2 clearing options not working add options select2 js clear all options select2 reset selected select2 select2 with clear button add to list selection in select2 append option to select2 reset select2 options select2 add html to option select2 reset selected select2 clear button append option in select2 reset select2 how to select option select2 select2 dynamically select options multi select dropdown search with dynamically add options all select2 selected value clear select2 addable option select2 reset option jquer add option select2 how to clear select2 how to append select2 to existing dropdown clear selected value in select2 clear selected value select2 select2 clear select value select2 add select all option select2 add neww option select2 select or add new select2 clear all option selected select2 clear all selected how to select2 set option how to clear select2 picker clear manually select2 add option one at a time javascript clear select2 select 2 clear options select2 add new option jquery select2 add option to list select2 reset all select2 clear selections select2 clear. select2 clear all data select2 create new option select2 clear all items add option in select2 select2 add how to trigger select2 clear Select2 add option and select select2 multiple clear all trigger unselecting select2 to clear option on clear select2 for each add select2 option select2 on change add select2 option how to clear select2 value clear val select2 select2 dropdown add button jqeury ajax select2 manual select2 add option to infront select2.val select2 jquery ajax append option set value select2 select 2 selected value jquery select option in select2 how to clear data in select2 affect select2 values dynamic select2 find option and trigger select a option in select 2 select2 add option selected how to set an element up the select2 select2:select javascript select2 select based on value how to remove data to select2 in javascript how to add data in select 2 how to make select2 empty selectable select2 add custom option select2 custom option select2 remove all options select2 multiselect on clear select2 init with data select2 options data select2 options select2 set selected option editable using select2 dropdown select2 clear selected select2 data selected jquery selected option select2 select2 add selected value SELEct 2 add selected value clear selectio value in jquery select2 select2 selected jquery select option change select 2 select2 multiple select dynamically add set select2 value select an option select2 add item in select 2 js example add item in select 2 js select2 jquery add option select2 add option ajax set value select 2 select 2 jquery add select2 select option programmatically append select 2 dropdown select2 add new option dynamically select2 add items bootstrap select2 clear selection remove a option from select 2 using jquery add new option to select 2 how to clear data from select2 dropdown select2 clear option select2 edit selected value add option to select2 js select2 select option select2 add an option select2 js set selected select2 option selected how to clear select2 selected value in js change select 2 manually select value for dynamic loading dropdown select2 select2 set options how to implement select2 in our select field select2 set selection select2 reset options jquery select2 reset selection select 2 resset select2 change selected option select2 set id select2 dropdown selected add remove options + select2 select2 reset data select2 dom clear select2 slecteed value select2 with ability to accept value not from the list select2 with ability to write unisted value select2 allow new value select 2 select a value add select2 to input add select 2 to input select2 add multiple option dynamically dynamicly add option to select2 by ajax add select2 list dynamically select2 example dynamic options select2 reset value jquery add item in select2 js inti value of select2 jquery set options to select 2 multiple select option append in select2 select2 value clear select2 selected value clear multiple options append in select 2 select value in select2 jquery select2 reset selected value select 2 dropdown add item add value in select 2 select2 jquery set value select2 on clear append option 0 select2 multiple update new options how to declare select 2 in html select2 dynamic option creation select2 dynamic select select2 add remove option dynamically select2 on clear select2 add data dynamically select2 options select on update select2 add options dynamically select2 add manually how to populate a select2 input using jquery set value on select 2 select2 allow clear one option clear select2 value select2 clear ajax select2 value change empty selection on change select2 clear select2 value in jquery select2 set option value .val select2 select 2 not clearing selected value select2 select option using jquery SELECT2 ADDABLE DROPDOWN select2 on select option select2 set by value select2 clear values jquery select2 set value jquery select2 set valuej select2 dropdown items with bigger then selected select2 set value jquery fill values in select2 one by one .val in select2 fill values in select2 select option in select2 jquery select2 clear item select2 insert at first select2 reset selection select2 clear select2 Clear select select2 empty selection select option select2 by value select 2 update select2.js clear select2 append options jquery select2 clearn option select2 add new option if not found select2 selected option jquery add select2 dropdown in add more in html select2 select option by value programmatically select2 selected value how to apply dynamic option creation of select2 select2 4 update dropdown list select2 add option dynamically select2 new option select2 dynamic add option clear selected value in select2 js select2 update selected value select2 clear all options Select2 Force Select select2 add new option select2 reset option select select 2 select values programaticalliy select2 change selected value select2 set value change select2 add value add data value to select2 options select2 reset value select 2 selected value selecting a select2 option jquery how to make a select2 to add value out of options select 2 Generating id properties select 2 dynamic multiple select2 dynamic options select2 multiple options select2 select option dynamically bootstrap select2 change option data select2 create option manually select2 create option dynamically select2 on reset select2 reset dunamic options select 2 reset dunamic options select2 how to know if programmatically select select2 programmatically select event select 2 set selected option select 2 option selected in jquery select2 set selected value select 2 set value select2 append new option select2 add new option ajax select2 dynamicaly select multiple values how to add option select2 SELECT2 apend data event select2 add button dynamically select2 add item to end select2 update options select2 update value select2 val set selected item in select2 how to select option in select2 in jquery how to add obtion in select2 in jquery select option in select2 using jquery select2 set selected trigger clear select2 select2 clear input select2 jquery append reset all select2 options how to select value in select2 jquery select2('data') set value select2 update select2 manually select select2 append option ajax select2 append option jquery select2 dropdown with option to add new item select2 select option by value how to clear select2 dropdown in jquery select2 selecting a select2 option select2 option reset adding or removing options to select 2 jquery js select2 clear list clear all selected options select2 clear select2 selected option clear select2 options select2 manually set value select2 add options select2 clear value select2 seelect without append select 2 select value js select2 add option select2 set value select2.js clear selection select2.js select nothing select2 select valus select2 reset select2 select using jquery select2 adding another id to select select2 add option clear select2 jquery jquery clear select2 js select2 preselect object jquery select2 add remove row bootstrap select2 add options clear selection select2 clear select2 selected value jquery select2 change valyue select2 value select2 select by value select 2 select item using jquery select2 optin selected clear select2 select2 clear selected value select2 multiple manual select select2 selected change button for select2 clear select 2 dropdown val select2 select value set select2('data') select2 set datasource programmatically select2 clear selection select 2 clear and set datasource select 2 set data select2 change value add option to multiple select2 select2 empty select 2 select by value clear select 2 option javascript select2 trigger ajax manually javascript select2 manual select 2 selected jquery select2 manually aselct select2 clear default add option to select2 jquery update select2 value jquery select2 set select2 value selected jquery change select2 option jquery select2 select value javascript jquery select2 set selected jquery select2 selected value set select2 value jquery jquery select2 clear cache change select2 value jquery insert values to select2 multiple js select2 reset value without append add val select2 jquery jsfields how to clear select2 option in jquery empty select2 jquery select select2 option jquery set selected option jquery select2 jquery select2 array update how to set value in select2 using jquery set value in select2 jquery select2 select value using jquery select2 ajax clear data fill select2 jquery select2 clear options
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source