简体   繁体   中英

Style text inside an HTML textarea

My problem is that I have textarea and want to find a specified string and mark all of its occurences (something similar to what regex101.com does with regex matches).

This leads me to a more general question (see my question title) and I would like to learn if the following can be applied to parts of text inside a textarea:

  • change font color
  • change background color
  • change font style (bold, italic)
  • change font size

Should I use something which already exists (like codemirror )?

I would also appreciate it if someone could explain the idea behind this (for example regex101.com has a textarea but also uses some span elements to highlight the matches)

Have you tried doing something like:

var textArea = document.getElementById("textArea");
textArea.style.color = 'Red';
textArea.style.backgroundColor = 'Black';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM