0

There is user input in textarea like "somefoo foo". I want to change foo word color to blue.Code below doesnt work!

<body>
<div><textarea rows="4" cols="50">somefoo foo</textarea></div>
<script>
var regx=new RegExp("foo");
var value=' otherfoo';
$("textarea").html( $("textarea").val().replace(regx,value.fontcolor('blue')));
</script>
</body>
tablex
  • 87
  • 1
  • 11
  • interesting...thanks!!! i will try to implement this and see how it works. – tablex Nov 15 '15 at 14:46
  • one more question: is it possible to create a link for a particular word inside textarea by implementing similar logic.What do you think? – tablex Nov 15 '15 at 14:48
  • Yes. You could modify one of the answers to wrap the word in an anchor rather than a span – Turnip Nov 15 '15 at 14:51
  • hi @Sexy Turnip...i tried to implement the answer that you suggested but they are all about highlighting not for giving color to text and this needs different approach i think, i managed to do that though using my own way.But there is a bug, i needed to make textarea 'color':'transparent' in order to show the text behind it, and when i do so, cursor disappears and how can i show cursor?is there a way to do that? – tablex Nov 17 '15 at 18:55

0 Answers0