Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of specific string

Does anyone know how I could change the color of a specific word if it is typed into a textarea? For instance, if the user types 'hello my friend', it would dynamically change 'hello' to green? Spent a large amount of time on google, and could not find anything very related. Thank you.

like image 879
Chris Avatar asked Feb 24 '23 12:02

Chris


2 Answers

textareas aren't designed to be selectively colored.

like image 82
Daniel A. White Avatar answered Feb 27 '23 15:02

Daniel A. White


You can't do it in a textarea field because its only content can be text, not HTML. You'll have to use an editable DIV or something, and then replace the word in string with <span>word</span> and apply a CSS class to the SPAN.

like image 32
Kon Avatar answered Feb 27 '23 16:02

Kon