Insert text to input or contenteditable element.
Install from npm:
$ npm install @kanety/insert-text --save
Insert text to textarea
:
<textarea>sample text</textarea>
import InsertText from '@kanety/insert-text';
InsertText.run('textarea', 'YOUR TEXT');
Insert text to contenteditable
element:
<div contenteditable="true">sample text</div>
import InsertText from '@kanety/insert-text';
InsertText.run('div[contenteditable]', 'YOUR TEXT');
Text is inserted at caret position by default.
Insert text at first position:
InsertText.run('textarea', 'YOUR TEXT', 'first');
Insert text at last position:
InsertText.run('textarea', 'YOUR TEXT', 'last');
The library is available as open source under the terms of the MIT License.