Select2 in a dynamic table

Hello guys,

I created this project :
This work only for the first line.
How can I do this for all my lines?

Thank you

uuuuuup please
thank you

The problem is that you are using the same id value for the <select> element in each new row. This is not allowed per the HTML specification, and $('#element') will only return the first element with that id value.

So in your #add_article click event handler, you need to figure out how to generate a unique ID value for each row’s <select> element. Something like this should work:

// Clone the row template and add it to the table.
// Generate a unique ID for the <select> in the new row.
var newSelectId = 'select' +;
// Update the ID of the <select> in the new row 
// (it should be the only one with an `id` of '#element'), 
// and initialize the Select2.
$('#element').attr('id', newSelectId).select2({tags: true});

I can confirm that this solution works. thanks
Here is the js fiddle.
Edit fiddle - JSFiddle - Code Playground