| <!doctype html> |
| <p id="start"><span style="font-size: 200%; color:red"> [!(5)#]</span>9abcdefghi</p> |
| <div id="start2">ABC</div> |
| <p><span style="font-size: 200%; color:red">(a)</span> bc</p> |
| <div id="end2">DEF</div> |
| <p id="end"><span style="font-size: 200%; color:red">[!(3)#]</span>789abcd</p> |
| <script> |
| const selection = window.getSelection(); |
| const start = document.getElementById('start'); |
| const end = document.getElementById('end2'); |
| // Select "^(5) to E|" |
| selection.collapse(start.firstChild.firstChild, 4); |
| selection.extend(end.firstChild, 2); |
| </script> |