Hi Ines,
I created a dropDown List using this js code:
function createList(list){
var dList = document.createElement('select');
dList.setAttribute("class","js-example-basic-single");
list.forEach(item =>{
var dOption = document.createElement('option');
dOption.setAttribute('value',item);
dOption.setAttribute('text', item);
dOption.innerText = item;
dList.appendChild(dOption);
})
return dList
}
l = ["one", "two", "THREE"];
var list = createList(l)
var container = document.getElementsByClassName('container')[0];
container.appendChild(list)
Everything worked fine! I tried to add a search bar to this dropDown List and nothing happened. This is what I added to the head of my page in order to do that.
<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.js-example-basic-single').select2();
});
</script>
My broser does not show any errors. Am I doing it wrong ?