Skip to content

Instantly share code, notes, and snippets.

@egorvinogradov
Last active February 5, 2023 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egorvinogradov/5d7f8752a3843b99ed80b843986f3aa4 to your computer and use it in GitHub Desktop.
Save egorvinogradov/5d7f8752a3843b99ed80b843986f3aa4 to your computer and use it in GitHub Desktop.
// INPUT
let text = '---';
let input = document.querySelector('input');
let event = new Event('input', { bubbles: true });
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
nativeInputValueSetter.call(input, text);
input.dispatchEvent(event);
// TEXTAREA
let text = '---\n1\n2';
let textarea = document.querySelector('textarea');
let event = new Event('input', { bubbles: true });
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set;
nativeInputValueSetter.call(textarea, text);
textarea.dispatchEvent(event);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment