I want to highlight word This
in the li element of ul using Rangy:
<ul>
<li>T<strong>hs is bea</strong>utiful.
<br>
</li>
</ul>
And at the run time I am ending up with a separate li wrapped surrounding the word This
and another li wrapped surrounding the remaining contents is beautiful
How to stop adding a separate li tag around the word This
My code is as below :
$scope.highlightTagStrings=function() {
var selection,selectedRange;
selection = rangy.getSelection(); //console.log(rSel);
var txt = selection.toHtml();
selectedRange = selection.getRangeAt(0);
selectedRange.deleteContents();
//var node = selectedRange.createContextualFragment('<span class="hilite ' + evalNum + '" name="' + sSel + '~' + eSel + '">' + txt + '</span>');
var node = selectedRange.createContextualFragment('<span style="background-color:pink" class="startIndex-' + startIndex + ' endIndex-' + endIndex + '">' + txt + '</span>');
selectedRange.insertNode(node);
selection.removeAllRanges();
return;
}
Can anyone help me regarding this?
's between](https://stackoverflow.com/questions/39324813/jquery-change-color-of-string-in-a-text-ignoring-brs-between) – Mirza Sisic Sep 25 '17 at 00:18