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
javascript jquery angularjs html5


source to share


No one has answered this question yet

Check out similar questions:

2414
How can I find out which radio button is selected using jQuery?
2132
Get selected text from dropdown (select field) using jQuery
1966
How can I select an element with multiple classes in jQuery?
1929
HTML 5: is this a site, <br/ "> or <br/">?
1799
Generating random integers in JavaScript within a specific range?
1375
Where should I put <script> tags in my HTML markup?
1184
jQuery get specific text of option tag
853
Element selection by data attribute
776
Get selected element of external HTML
770
HTML text input only allows numbers to be entered



All Articles
Loading...
X
Show
Funny
Dev
Pics