+ 2

Html font color

im aware of how to have a font color. But what is the best way to have a color pattern without having to place the font color code before and after each and every letter?

11th Nov 2016, 3:46 AM
Aquarius
Aquarius - avatar
5 Réponses
+ 9
var textToChange = $("#txt").text(); for(var i = 0; i < textToChange.length; i++) { var newSpan = $("<span />"); .text(textToChange[i]); .css("color", i % 2 == 0 ? "green" : "red"); $("#txt").append(newSpan); } It's something like this.😉
14th Jan 2017, 3:32 PM
Cezar
Cezar - avatar
+ 2
Using CSS you can assign colors to each type of element, class or ID. I strongly suggest you to make the sololearn's CSS course
11th Nov 2016, 10:50 AM
Carlos Eduardo Carvalho Mendes
Carlos Eduardo Carvalho Mendes - avatar
+ 2
i will when i finish html, but will it show me how to insert a different color for each letter?
11th Nov 2016, 12:41 PM
Aquarius
Aquarius - avatar
+ 2
now i understood what you want to do. To achieve this you should use a program language to manipulate the string and wrap each letter inside a HTML element. Then you could dynamically Collor each letter individually
11th Nov 2016, 12:55 PM
Carlos Eduardo Carvalho Mendes
Carlos Eduardo Carvalho Mendes - avatar
+ 2
oh ok thats what i was avoiding but ok thanks Carlos
11th Nov 2016, 1:07 PM
Aquarius
Aquarius - avatar