How do I edit the selected text of a textarea form element?
EDIT: as in edit it in-place, replacing the orignal text.
This works:
function replaceIt(txtarea, newtxt) { $(txtarea).val( $(txtarea).val().substring(0, txtarea.selectionStart)+ newtxt+ $(txtarea).val().substring(txtarea.selectionEnd) ); } $("button").on('click', function() { replaceIt($('textarea')[0], 'fun') })
Hello world. Replace with fun