Get textarea value on change


Given a textarea element:

<textarea></textarea>

Input

To get the textarea value on input event:

document.querySelector('textarea').addEventListener('input', function (event) {
  console.log(event.target.value);
});

This logs the value every time the value changes.

Change

To get the textarea value on change event:

document.querySelector('textarea').addEventListener('change', function (event) {
  console.log(event.target.value);
});

This logs the value after the textarea element loses focus.



If you enjoyed this post, please consider supporting this site!