JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css">
<h2 style="padding:0px;margin:0px">
JSFiddle Example (Fixed & Working)
</h2>
<p style="padding:0px;margin:0px"><em>Using the latest release of select2 (4.0.13)</em></p>
<br/><br/>
<button id="add-cust">Add +</button>
<br/>
<table id="job-customers">
<thead>
<th>#</th>
<th>Customer</th>
</thead>
<tbody>
<tr id="row-customer-1">
<td>1</td>
<td id="selcol">
<select id="sel" class="select2" data-placeholder="Choose">
<option></option>
<option value="a">ABC Co. INC</option>
<option value="b">Mega Enterprises</option>
<option value="c">Material Supply Co.</option>
<option value="d">A-Z Tools & Stuff</option>
</select>
</td>
</tr>
</tbody>
</table>
CSS
.select2-container {
min-width: 200px;
padding: 5px;
}
JavaScript
$(document).ready(function () {
$(".select2").select2(); //INITIALIZE SELECT2 ELEMENTS ON DOM LOAD
//BUTTON CLICK
$("#add-cust").click(function () {
let table = document.getElementById("job-customers");
let last_customer = parseInt(table.tBodies[0].rows.length, 10);
let new_customer = last_customer+1;
let row = table.insertRow(-1);
row.setAttribute('id', 'row-customer-'+new_customer);
row.setAttribute('class', 'customer');
let cell1 = row.insertCell(-1);
let cell2 = row.insertCell(1);
cell1.innerText = new_customer;
//LOOP ROWS IN TBODY COL2 & DESTROY SELECT2 ELEMENTS
$("#job-customers").find("tbody td:nth-child(2)").each(function () {
$(this).children("select")
.select2("destroy")
.end();
});
//CLONE & APPEND
$("#row-customer-" + last_customer + " td:nth-child(2)")
.children("select").clone()
.attr('id', 'sel-'+new_customer) //UPDATE ID USING ROW/CUST #
.appendTo(cell2);
//RE-INITIALIZE SELECT2 ELEMNTS
$(".select2").select2();
});
});