0

Assume an HTML textarea that you bound the change event to it with textarea.onchange = ..., or textarea.addEventListener('change', ...).

I want to modify it like textarea.textContent = '...' or textarea.value = '...' and this to trigger the aforementioned change event.

This is not a duplicate question as the others I've found here imply the use of jQuery. I do not want to use jQuery, I know it saves lives and stuff but I'm fine without it, thanks. :^)

Ale Morales
  • 2,728
  • 4
  • 29
  • 42
  • So you mean like a watcher that triggers the change event automatically whenever you use `.textContent` or `.value` on that textarea element anywhere in your code? – Constantin Groß May 03 '19 at 19:35
  • @Connum I can define a custom watcher sure but, is there a way for that to happen "automatically"? I mean, like having the DOM trigger the event by itself? Another thing could be to just explicitly trigger the 'change', akin to .click(), but I do not know how to do that. – Ale Morales May 03 '19 at 19:38
  • Well then you could either make your change event callback a named function and call that any time you update the textarea, or you could trigger the change event manually, see https://stackoverflow.com/questions/2490825/how-to-trigger-event-in-javascript – Constantin Groß May 03 '19 at 19:43
  • @Connum dispatchEvent is what I was looking for, thanks! – Ale Morales May 03 '19 at 19:45

0 Answers0