0
votes

I am having html input textbox with value of "Hello World".

I want to change the text color of 'Hello' to red using jquery.

Example:

Textbox Value is Hello World. Hello font color is Red

1
@DaveBriand wish we could make that a pre-requisite before posting on the tags of this question! - Rob Schmuecker
@RobSchmuecker deleted my comment because I don't think there's a jquery course on codecademy :) - Dave Briand
Please post any relevant code snippets that you have tried. - War10ck
@DaveBriand way to go ... Ooops! :-) - Rob Schmuecker
I am tried the following code. var strVale="[email protected],[email protected],[email protected]"; var str = $("#txtGetValue").val(); $("#txtGetValue").val(str.replace(strVale, "<span class='spanError'>" + strVale + "</span>")); - Murugan

1 Answers

1
votes

I think you can't just change Hello to red and change world to another color. but there is a solution to do this, is to create a div and put spans inside div with different colors, and define click, keyup, keydown events

<div class="input">
  <span class="red">Hello</span>
  <span class="green">world !</span>
</div>

The question has been asked and answered here.