Skip to content

Instantly share code, notes, and snippets.

@AlphaNerd
Created May 27, 2015 14:16
Show Gist options
  • Save AlphaNerd/5609d16937c474f03217 to your computer and use it in GitHub Desktop.
Save AlphaNerd/5609d16937c474f03217 to your computer and use it in GitHub Desktop.
Basic jQuery function to split Joomla tittles into multiple <span>. Used for multi-colored titles in Joomla where first word is different color than rest. Simply supply selector, and adjust phrase split.
jQuery('.home #bottom_in h3').each(function(i,val){
var titleWords = val.innerHTML.split(" ");
var first = titleWords[0] + " ";
var second = "";
if (titleWords.length > 2){
for (i=1;i<titleWords.length;i++){
second += titleWords[i]+" ";
}
}else{
second = titleWords[1];
}
jQuery(this).html("");
jQuery(this).html("<span class='firstWord'>"+first+"</span><span class='secondWords'>"+second+"</span>");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment