Change the color of a specific line

Does anyone know how I can change the color of a certain word if it is entered in the text area? For example, if a user calls “hello my friend”, will he dynamically change “hello” to green? Spent a lot of time on google and could not find anything very connected. Thanks.

+4
source share
5 answers

textarea not intended for selective coloring.

+6
source

You cannot do this in the textarea field, because its only content may be text, not HTML. You will have to use an editable DIV or something else, and then replace the word in the string with <span>word</span> and apply the CSS class to the SPAN.

+1
source

In textarea you cannot. But there is the possibility of an "editable div". See http://codemirror.net/

+1
source

HTML specifications do not allow the use of different fonts in the same textarea element. You cannot do this.

However, you can create an editor with JS that will do pretty much what you want. These things are usually quite large projects, so you probably want to do something. The list is here .

0
source

enter image description here

0
source

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


All Articles