Select2: Not working for dynamically inserted elements

Created on 10 Feb 2016  路  3Comments  路  Source: select2/select2

Is it possible to make this working for dynamically (using Jquery and not ajax ) elements?

Basically, using JQuery I would add a new row with a select element and want to bind that new element with the select2.

capture

Most helpful comment

setTimeout(function(){
$('.select2').select2();
}, 100);
use this when adding new row

All 3 comments

It was not difficult to make it work:

/*Bind select to the newly created country selectbox*/
$("#country"+next).select2({
   placeholder: "Select a country",
   allowClear: true,
   data: data
}); 

setTimeout(function(){
$('.select2').select2();
}, 100);
use this when adding new row

Check if when you copy the new country select element you keep the element id. If so you must delete the id

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanderhahn picture sanderhahn  路  4Comments

ghost picture ghost  路  3Comments

fabienheureux picture fabienheureux  路  3Comments

eved42 picture eved42  路  3Comments

videsignz picture videsignz  路  3Comments