A
A
Andreas Sjoberg2017-05-25 10:42:02
JavaScript
Andreas Sjoberg, 2017-05-25 10:42:02

How to implement text highlighting depending on what data is in JSON?

Friends, what a day I've been struggling with this problem.
There is a text input field on the page and a button. A person enters text, presses a button, and a similar type of json is returned to him:

[
    172,
    "НАТО",
    "Abbr"
],

Where 172 is the serial number of the character in the text, i.e. the letter "H" in the word "NATO" is the 172nd letter in the text input field. And this word must be highlighted, like all other words that have "Abbr". There can be as many values ​​as "Abbr" as you like.
That is, the initial data is as follows: there is the number of the letter with which everything should begin, there is a word that needs to be highlighted, and there is a group of words, depending on which there will be a different highlight color.
I typed all the test JSON into the CodePen .
Help, please, to solve this problem.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question