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 (NOT working)
</h2>
<p style="padding:0px;margin:0px">From SO Question <a href="https://stackoverflow.com/questions/17175534/cloned-select2-is-not-responding" target="blank">https://stackoverflow.com/questions/17175534/cloned-select2-is-not-responding</a><br/>
<em>Using the latest release of select2 (4.0.13)</em></p>
<br/><br/>
<div id="contents">
<select id="sel" data-placeholder="-Select education level-">
<option></option>
<option value="a">High School</option>
<option value="b">Bachelor</option>
<option value="c">Master's</option>
<option value="c">Doctorate</option>
</select>
</div>
<br>
<button id="add">add a dropdown</button>
CSS
#contents div.select2-container {
margin: 10px;
display: block;
max-width: 60%;
}
JavaScript
$(document).ready(function () {
$("#contents").children("select").select2();
$("#add").click(function () {
$("#contents")
.children("select")
// call destroy to revert the changes made by Select2
.select2("destroy")
.end()
.append(
// clone the row and insert it in the DOM
$("#contents")
.children("select")
.first()
.clone()
);
// enable Select2 on the select elements
$("#contents").children("select").select2();
});
});