I want to put some specified text (where possible/any editable field) before and after any selected text in an HTML document.
document.getSelection() or document.selection.createRange().text returns only the text itself not the position.
Is there anyway to replace the selected text? Anyway to insert specific text before and after selcted text anywhere in the document?
I want to put some specified text (where possible/any editable field) before and after
Share
Here’s a cross-browser function to do this, which works in all major browsers and caters for the vastly different way IE does this compared to other browsers.
Live example: http://jsfiddle.net/timdown/UWExN/64/