I am having one issue, I need to replace the selected text with some HTML for annotation functionality. I reach upto replacing the text. but now the issue is document may contain repetitive string and when I tried to replace it, its always replace first instance in paragraph. My code is give below.
Need to replace all the annotation from json at respective position. Can anyone help me how to replace/insert text at precise location?
for (var i = 0; i < AnnotationDetails.length; i++)
{
//locate the string between start and end point
var TextToReplace = OutPutText.substring(AnnotationDetails[i].start, AnnotationDetails[i].end);
//prepare replace text
var AnnotationClass = '<mark data-entity="' + AnnotationDetails[i].label + '" data-id="' + AnnotationDetails[i]._id + '">' + TextToReplace + '</mark>';
var AnnotationText = $('.output').html();
//put text back as html to div
$('.output').html(AnnotationText.replace(TextToReplace, AnnotationClass));
}
Below given the json.
"annotations": [
{
"_id": "FWFpjaec",
"start": "6123",
"end": "6155",
"label": "support"
}
]
I have paragraph where string "Planning and Conservation League" available at two location. so whenever I try to replace second instance, javascript always replace first one. Start and end point in json is precise, but any way to replace it at precise location??