Sometimes, we want to listen to the input event with jQuery.
In this article, we’ll look at how to listen to the input event with jQuery.
Listen to the input Event with jQuery
To listen to the input event with jQuery, we can call the on method with 'input' as the first argument.
For instance, we write:
<textarea></textarea>
<div>
</div>
to add the textarea and the div to display the inputted value.
Then we write:
$('textarea').on('input', () => {
const text = $('textarea').val();
$('div').html(text);
});
to call on with 'input' with a callback to get the textarea ‘s value with:
$('textarea').val()
and assign it to text .
Then we get the text and put it in the div with:
$('div').html(text)
Conclusion
To listen to the input event with jQuery, we can call the on method with 'input' as the first argument.