Skip to content

Instantly share code, notes, and snippets.

@simbus82
Created October 14, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbus82/a73507d33a03a9a456dc to your computer and use it in GitHub Desktop.
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.
<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