By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Highlight characters in a string

P: 1
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
Nov 29 '13 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
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.
Nov 29 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.