xxxxxxxxxx
1
<div class="form-outline clear-example" data-mdb-datepicker-init data-mdb-input-init>
2
<input type="text" class="form-control" id="exampleDatepicker" value="18/12/2024"/>
3
<label for="exampleDatepicker11" class="form-label">Select a date</label>
4
</div>
5
<button type="button" class="btn btn-primary" id="clear" data-mdb-ripple-init>Clear</button>
1
1
xxxxxxxxxx
1
const clearButton = document.getElementById('clear')
2
const inputEl = document.getElementById('exampleDatepicker');
3
4
clearButton.addEventListener('click', ()=> {
5
inputEl.value = "";
6
const inputEvent = new Event('input', { bubbles: true });
7
inputEl.dispatchEvent(inputEvent);
8
inputEl.classList.remove('active');
9
})
Console errors: 0