xxxxxxxxxx
1
<div class="container mt-5 ms-5">
2
<select id="singleSelection" class="select">
3
<option value="1">One</option>
4
<option value="2">Two</option>
5
<option value="3">Three</option>
6
<option value="4">Four</option>
7
<option value="5">Five</option>
8
</select>
9
<button id="select4" class="btn btn-primary mt-3">
10
Select 4
11
</button>
12
<button id="select9" class="btn btn-danger mt-3">
13
Select 9
14
</button>
15
</div>
1
1
xxxxxxxxxx
1
const singleSelect = document.querySelector('#singleSelection');
2
const singleSelectInstance = mdb.Select.getInstance(singleSelect);
3
const select4Btn = document.querySelector('#select4');
4
const select9Btn = document.querySelector('#select9');
5
6
select4Btn.addEventListener('click', () => {
7
singleSelectInstance.setValue('4');
8
});
9
select9Btn.addEventListener('click', () => {
10
alert('Set 9');
11
singleSelectInstance.setValue('9');
12
alert('Never gets here...');
13
});
Console errors: 0