<p id="p">Example: <i>italic</i> and <b>bold</b></p>
From <input id="start" type="number" value=1> – To <input id="end" type="number" value=4>
<button id="button">Click to select</button>
<script>
button.onclick = () => {
let range = new Range();
range.setStart(p, start.value);
range.setEnd(p, end.value);
// طبّق التحديد، سيُوضَّح لاحقا
document.getSelection().removeAllRanges();
document.getSelection().addRange(range);
};
</script>
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.