xxxxxxxxxx
1
<div class="container mt-5 pt-5">
2
<button class="btn btn-primary">
3
load data
4
</button>
5
<div class="wrapper mt-5">
6
<select class="select" id="mySelect">
7
<option disabled value="">data is loading, please wait</option>
8
9
</select>
10
</div>
11
</div>
1
1
xxxxxxxxxx
1
const wrapper = document.querySelector('.wrapper');
2
const btn = document.querySelector('.btn');
3
const selectString = `
4
<select class="select" id="mySelect">
5
<option value="1">One</option>
6
<option value="2">Two</option>
7
<option value="3">Three</option>
8
<option value="4">Four</option>
9
<option value="5">Five</option>
10
</select>
11
`;
12
13
btn.addEventListener('click', () => {
14
const select = document.querySelector('#mySelect');
15
const selectInstance = mdb.Select.getInstance(select);
16
selectInstance.dispose();
17
wrapper.innerHTML = "";
18
wrapper.insertAdjacentHTML( 'beforeend', selectString );
19
const mySelect = new mdb.Select(document.getElementById('mySelect'))
20
})
Console errors: 0