Hello

How to add style to only that word where cursor is placed with document.getSelection()?

25 Views Asked by At

I want to apply the style only to that word where cursor is placed.

<p id="p">Hello</p>
<script>
  let range = new Range();
  range.setStart(p.firstChild, 2);
  range.setEnd(p.firstChild, 4);

  // toString of a range returns its content as text
  console.log(range); // ll
</script>
0

There are 0 best solutions below