Created
October 14, 2014 18:08
-
-
Save simbus82/a73507d33a03a9a456dc to your computer and use it in GitHub Desktop.
Aggiunge uno span attorno alle prime 3 parole rilevando lo spazio che le divide. Assegnando stile alle 3 classi è possibile creare titoli con colori diversi per le prime parole.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
jQuery(document).ready(function() { | |
jQuery('h3').each(function(){ | |
var text = jQuery(this).text().split(' '); | |
if(text.length == 1){ | |
text[0] = '<span class="firstWord">'+text[0]+'</span>'; | |
} | |
if(text.length == 2){ | |
text[0] = '<span class="firstWord">'+text[0]+'</span>'; | |
text[1] = '<span class="secondWord">'+text[1]+'</span>'; | |
} | |
if(text.length == 3){ | |
text[0] = '<span class="firstWord">'+text[0]+'</span>'; | |
text[1] = '<span class="secondWord">'+text[1]+'</span>'; | |
text[2] = '<span class="thirdWord">'+text[2]+'</span>'; | |
} | |
jQuery(this).html( text.join(' ') ); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment