Select2 in a dynamic table

Hello guys,

I created this project : https://jsfiddle.net/zarkoffe/vksnoxhr/19/
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.
Table_noms_messages.appendChild(TR_Base.cloneNode(true));
// Generate a unique ID for the <select> in the new row.
var newSelectId = 'select' + Date.now();
// 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