Hello! Is there any way to color keywords inside a <textarea> tag? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Hello! Is there any way to color keywords inside a <textarea> tag?

My idea is to create a programming environment in a textarea. I mean color strings, keywords etc. Anyone can help please?

10th Dec 2019, 8:15 PM
Csongor Kertesi
Csongor Kertesi - avatar
5 ответов
+ 1
I had the same idea before, but I wasn't able to find a solution. The only thing I was able to come up with was reading the textareas content and then replacing the words with html span elements that csn be colored using css. The resulting text is then being innerHTMled to a preview element.
11th Dec 2019, 12:07 PM
Jakob Meier
Jakob Meier - avatar
+ 1
yes but you cant change the cursor position
11th Dec 2019, 1:05 PM
Jakob Meier
Jakob Meier - avatar
0
Jakob Meier Thank you for the answer. Yes, I have an idea to do it like that. I viewed many online colored text editors, and I'm trying to clone them. I was interested in an easier way :)
11th Dec 2019, 12:56 PM
Csongor Kertesi
Csongor Kertesi - avatar
0
the only problem is that you cannot really click on the text to edit it - you still have to edit the text in the textarea
11th Dec 2019, 1:01 PM
Jakob Meier
Jakob Meier - avatar
0
Jakob Meier :/ Yes, but in JS there is a focus function, so when you click the text, it can say InvisibleTextare.focus()
11th Dec 2019, 1:04 PM
Csongor Kertesi
Csongor Kertesi - avatar