Reputation: 149
The title I used above is pretty confusing as far as understanding what I mean, so to further explain myself...I have a textarea, still with me? Alright, I want to use either jquery or javascript to change the color of certain words if they are typed in while not changing other color of text kind of like the code example that you see below. Anyone have any ideas of how one would get around to doing this?
If you don't want to do this a link to a tutorial would be great as well!
EXAMPLE
<textarea spellcheck="false" placeholder="Type your code here...">
</textarea>
Upvotes: 0
Views: 227
Reputation: 10617
This cannot be done with a textarea
, but I wrote program that sort of does what you speak of here. You have to use a div
or something then split every character into an Array, then join the Array into a String with spans as the glue, then go through the DOM using a RegExp testing for each character as a childNode[number] or something, then use JavaScript to change the style.color. This is a task for a programmer that really knows what they are doing.
Upvotes: 0
Reputation: 9576
You can't do that with a textarea
. You will need to wrap the different colored words in something like span
tags.
Have a look at ACE or CodeMirror to do this sought of thing with a library:
Upvotes: 1