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

T-Nagui picture T-Nagui  路  3Comments

jiny90 picture jiny90  路  3Comments

fr0z3nfyr picture fr0z3nfyr  路  3Comments

dnohr picture dnohr  路  3Comments

ethanclevenger91 picture ethanclevenger91  路  3Comments