I am trying to trigger the onchange event on a span element. The event is not triggered at all. How can I make it happen? Here is my code:
First method I tried
JavaScript
x
4
1
document.getElementById(seconds).addEventListener('change', (event: MutationEvent & { path: any }) => {
2
console.log('span has changed')
3
}
4
Second method
JavaScript
1
4
1
document.getElementById(seconds).onchange((event) => {
2
console.log('span has chanegd')
3
}
4
Advertisement
Answer
the onchange event only works on inputs, selects and textareas. You will need another event.