I've searched but cannot find a solution to increment the font color (eg. lightness +10%) for each of 3 or 4 words in a title. The font color will be initially set in SCSS with a color var.
Example Title:
Here Is My New Title
In this example, lets say the title was 'dark blue'.. the words would be:
Here = darker blue
Is = navy blue
My = medium blue
New Title = light blue
There is a similar post here: JavaScript Text Color Change To Each Word In Array but this is searching for keywords in an array, not each word of a string.
I've also come across basic CSS/HTML only solutions like this, which won't work: HTML: Changing colors of specific words in a string of text
NOTE: I will be returning the title (string) in a php variable - in case there is a solution in PHP.
GOAL: I need to increment the font color (or even wrap consecutive words in spans and increment the SCSS var) for each word in a string.. open to suggestions.
UPDATE I've added a jsfiddle link (http://jsfiddle.net/revive/xyy04u7d/) to show the JS implementation, thanks to Tushar, with some changes to include ampersands in the regex.
Here is the PHP implementation:
<?php
$title = "SIMPLE TITLE & WITHOUT COLORS";
$words = preg_split('/\s+(?!&)/', $title);
?>
<h3 class="colors blue">
<?php foreach($words as $word):?>
<span><?php echo $word; ?></span>
<?php endforeach; ?>
</h3>