JavaScript - how can I set ontype event on input text element?
After checking MDN Documentation I have noticed there is no ontype
event for <input type="text">
element.
I don't want to use onchange
event.
Is there some way how to handle event always on text change?
You should use oninput
event.
e.g.
// ONLINE-RUNNER:browser;
<input type="text" oninput="console.log(this.value)" />
OR:
// ONLINE-RUNNER:browser;
<input id="element" type="text" />
<script>
var element = document.querySelector('#element');
element.addEventListener('input', function() {
console.log(element.value);
});
</script>