Skip to content

Instantly share code, notes, and snippets.

@andredublin
Created September 13, 2011 17:54
Show Gist options
  • Save andredublin/1214505 to your computer and use it in GitHub Desktop.
Save andredublin/1214505 to your computer and use it in GitHub Desktop.
Find text of html element, replace with modified text
function newText(obj, text, classy) {
var hLen = text.length,
firstIdx = text.indexOf(' '),
startStr = text.slice(0, firstIdx),
endStr = text.slice(firstIdx, hLen),
newStr = startStr + '<span class="'+classy+'">' + endStr + '</span>';
$(obj).html(newStr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment