How to add a line to a text area with different colors?

I am trying to figure out how to write a function in which I pass a string, and that string is added to the text box. I can do this, but I want to analyze this line and change the color in different parts of the line.

In other words, find the words "select", "where" and turn them blue. Then find the words "AND", "OR", "<" and turn them into gray color, and everything that is between two single quotes will be red.

I hope for a simple function, and not for the use of syntax highlighting libraries, I'm not even sure that they will work with strings that are dynamically generated.

How can i do this? Can I use jQuery if this makes things easier?

Thank you all

+3
source share
1 answer

the text inside the elements <textarea>is just plain text, which means that it cannot be styled. what you can do is create a div with contenteditableand work with it, check this link for a link: http://www.west-wind.com/Weblog/posts/778165.aspx

+2
source

Source: https://habr.com/ru/post/1757734/


All Articles