I have written a text editor using JavaScript.
Here I am not storing the written text in any variable, Now I want to replace some text/string of some selected text with other text/string.
Can anyone suggest me, how to do it using JavaScript.
T开发者_如何学Pythonhanks
If im understanding you correctly the following script could help you:
var selectedText = document.selection;
if (selectedText.type == 'Text') {
var newRange = selectedText.createRange();
var replacedText = newRange.text.replace("replacingText", "textToreplace);
}
Then the variable replacedText is the replaced version of your selected text.
精彩评论