'textarea events not triggered upon .val()

When I run

$("textarea").val("hello");

the events that Firefox developer tools (F12) reports are bound to this textarea,

,

are not triggered. How do I trigger them?

Running $("textarea").val("hello"):

Manually inputting text:

This textarea is on a website that has all sorts of code to prevent automated entry into the textarea. Even running a JavaScript or jQuery .click() on the textarea doesn't select it.

Appending .change(), as suggested by an answer to "val() doesn't trigger change() in jQuery", doesn't work for me, either.



Solution 1:[1]

The issue is that events not bound with jQuery cannot be triggered with jQuery, so you will have to trigger the change event using JavaScript:

let element = document.getElementById(idOfTextArea);
element.dispatchEvent(new Event('change', { 'bubbles': true }));

source: this answer to "How to trigger event in JavaScript?"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Geremia