Highlight characters in a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • victorb
    New Member
    • Nov 2013
    • 1

    #1

    Highlight characters in a string

    Hi,
    First of all, I'm a rookie in Javascript :(
    I'm trying to make an statement in jscript to color letters from a text, but it seems it's not so easy.
    More precisely: It is necessary to color letters as follows: first letter red, the second one black, the third red again....an so on.
    I don't know hot to set the condition in order to do that.
    I've tried with FOR and IF.

    Thank you
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    first of all you need (I am assuming that you are working on a website) to wrap up each letter in an inline element (e.g. <span>) and then you can give each of those elements the desired colour via CSS.

    on a more advanced stage you can wrap only each second letter to give it a different colour than the base text.

    Comment

    Working...