1

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?

Mirza Sisic
  • 2,401
  • 4
  • 24
  • 38
Babu.Babu
  • 11
  • 3

0 Answers0