Is it possible to register an event for changing html input value in javascript?
I mean I have an input. And when I type into it an event is registered, but when I update its (inputs) value through javascript the input event is not called. What is a workaround here?
For example, when you type into input the resulting text is updated, but when you clear the input using button (in other words through javascript) the input event is not registered.
html
<input id="inpt" oninput="updateText()" />
<div id="txtDiv">
resulting text
</div>
<button id="btn">
Click
</button>
js
const input = document.getElementById("inpt");
input.addEventListener('input', function() {
const resultingText = document.getElementById("txtDiv");
resultingText.innerHTML = input.value;
alet("called");
});
const btn = document.getElementById("btn");
btn.addEventListener('click', function() {
input.value = "";
});
keyupevent but it may be bad practice I don't know