I have a textarea and a button. Clicking the button causes text to be inserted into the textarea.
Is there a way to allow a user to press Ctrl/Cmd+z to undo the inse
You need to insert the text in a special way so the user can use the normal undo/redo behaviour.
var textEvent = document.createEvent('TextEvent'); textEvent.initTextEvent('textInput', true, true, null, "new text"); document.getElementById("your-textarea").dispatchEvent(textEvent);