Apply CSS background color only to the word set in the paragraph in the text box

I have textarea with some lines of text. The text contains alpha, numeric and special characters. I would like to apply CSS background colors only to some words (just to highlight them) in this text. For example, apply the background color only to numbers in the text box. Please let me know how to do this. Suggestions are welcome.

+6
source share
3 answers

There is no way (what I know) to do this using pure HTML and CSS. You will need to use JavaScript.

Option 1 Use an existing jQuery plugin. A quick search led me to this and an updated plugin here .

Option 2 Throw yours. You would like to use the search () function to find the location of words, and then add span wrappers around the words.

<style>.highlighted{background-color:yellow;}</style> ... <span class="highlighted>HIGHLIGHT ME</span> 

The only real advantage of this is that you can use regular expressions to provide more flexibility in what you highlight. It also allows you to avoid jQuery if it is not your cup of tea.

+2
source

The only way I can do this is to wrap the required text in some html to style it. For this, I get a separate textarea text output, see here: http://jsfiddle.net/mhPGc/8/

0
source

You use the span tag for this problem, you first set the id for the text area, then use this style code

 #textarea span{ background:url(img.jpg) or #etc; } 
-2
source

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


All Articles