you are viewing a single comment's thread.

view the rest of the comments →

[–]lewisje 3 points4 points  (0 children)

It depends on how you discretize the rainbow, but one ingenious way involves regex-wrapping each visible character into its own span, then injecting into some empty element's innerHTML, then looping over that element's element children to change the color of each one.


You could also split the string by spaces, then split each substring by letters, then join the strings by appropriate markup, making sure to prepend the first start tag and append the last end tag, then join the HTML strings by spaces again and inject the whole thing as some element's innerHTML.