I am trying to replace text in a text field using TextEvent / textInput events as follows:
var textarea = $('#my_textarea'), text = "Hello world !", selection = {'start': 4, 'end': 6}; var event = document.createEvent('TextEvent'); event.initTextEvent('textInput', true, true, null, text, 9, "en-US"); textarea.focus(); textarea[0].setSelectionRange(selection.start, selection.end); textarea[0].dispatchEvent(event);
This works fine in Chrome, but not in Internet Explorer 9: part of the text is well selected, but it does not change: /
I followed what was written here: Javascript textarea undo redo and here http://help.dottoro.com/ljuecqgv.php with no luck.
What am I missing?
Thank you for your help!
Note. I use TextEvent instead of just replacing text with val() , because I want to use the Undo / Redo system.
source share