I'm trying to extend a user's text selection with JavaScript. The selection is across multiple non input elements.
I have successfully extended the text being captured in the selection using selection.setBaseAndExtent.
The problem: how do I update the visual as well? I want the user to see that the text selection has been extended. Is it possible to change the visual selection across elements?
Nothing I've tried so far has shown the selection changing, even the captured text does change. I've tried using different methods of selection and range. Is it possible to do this across sibling elements, rather than all nodes in the selection being descendants of one element (as in this answer: Selecting text in an element (akin to highlighting with your mouse))
This is a simplified version:
<div class="a">
<div class="one">text</div>
<div class="two">text</div>
</div>
<div class="b">
<div class="three">text</div>
<div class="four">text</div>
<div class="five">text</div>
</div>
<div class="c">
<div class="six">text</div>
</div>
If the user selects divs two, three & four, I want to extend the selection to include divs one, two, three, four & five. I want to extend the selection displayed to show this
(I am happy using vanilla js or jquery)