xxxxxxxxxx
1
<!-- Default switch -->
2
<div class="m-5 form-check form-switch switch1">
3
<input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" />
4
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
5
</div>
6
1
1
xxxxxxxxxx
1
const switch1 = document.querySelector('.switch1');
2
3
document.querySelector('.form-check-input').addEventListener('click', () => {
4
if (switch1.querySelector('.form-check-input').checked) {
5
switch1.querySelector('.form-check-label').innerText = 'checked';
6
} else {
7
switch1.querySelector('.form-check-label').innerText = 'not checked';
8
}
9
});
Console errors: 0