0

I have an index(int) and an offset(int) related to body element, and I want to highlight those characters.

I don't know how to do this.

I've tried windows.getSelection(), but it is so complex

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ata Iravani
  • 2,146
  • 7
  • 29
  • 40
  • 1
    Have you considered `document.execCommand()`? There are `BackgroundColor` and `HiliteColor` commands that may do what you want. See this answer, for example: http://stackoverflow.com/a/3224513/96100 – Tim Down Jan 04 '12 at 14:24
  • no that's not what I meant. I wanna highlight characters by client-side script. – Ata Iravani Aug 22 '12 at 08:18
  • I don't really follow. The linked answer is written in client-side JavaScript. – Tim Down Sep 07 '12 at 14:48
  • `I've tried windows.getSelection(), but it is so complex` you should show what you have tried in form of a [mcve] and explain where it fails and what the expected selection is. – t.niese Feb 22 '22 at 19:45

0 Answers0