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