Selecting range text using html tags

I have a range selection problem, I saw some of the ans on the stack above the stream, I tried something, doesn't work.

Problem

The text as shown below will contain text with html tags

  Test  

The function should only select text in the side of html tags

I tried following but it doesn't work

function makeSelection() {
    var start = 3;
    var end = 9;
    var child = 2;

    var parent = document.getElementById('data');
    var range = document.createRange();
    range.setStart(parent.childNodes[child], start);
    range.setEnd(parent.childNodes[child], end);
    var sel = window.getSelection();
    sel.removeAllRanges();
    sel.addRange(range);   
}

      

will dynamically add html tags to the div, the value is present in the center like

  Test  

The function should only select the text Test. Please provide some information to resolve this issue.

+3


source to share





All Articles