tags:

views:

38

answers:

1

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.

Thanks

+1  A: 

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.