I am trying to select a part of the text similar to selecting it with a mouse.
I referred to this example here: How to select part of a text using select method?.
by using this code I'm able to select all content in the element (by providing the element id). however, I am unable to select only the desired part.
with the following code, I'm able to select all the contents.
var selection = window.getSelection();
var txt = document.getElementsByClassName("xyz");
var range = document.createRange();
range.selectNodeContents(txt);
selection.removeAllRanges();
selection.addRange(range);
i want to modify the code in such a way that by providing a kewyword and element id I want to slect all the instance of the keyword in that element id.
further, I want to use a loop function to loop through all the instance of the keyword and modify the text. ex: get a substring from the text etc.
One Two One Two Three
`, and you want `One`, it'll return `OneOneOne`? – Jack Bashford Mar 25 '19 at 07:36