'How can I highlight text using JavaScript?

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source