I am trying to replace the selected selected (marked) text from an element.
Here's how I got the selected text so far:
var markArea = $('.ElementText textarea').get(0); var text = markArea.value.substring(markArea.selectionStart, markArea.selectionEnd);
So, if I have something like this in the text box: “apple banana apple orange” and mark the third word (apple), I want to exactly replace what I have indicated, without any other cases of “apple” in the text box .
Is there a way to specify the start and end areas where the code should look for a replacement in the string?
source share