/ Published in: jQuery
Usage: $(selector).addCaps();
Expand |
Embed | Plain Text
jQuery.fn.addCaps = function() { this.each(function () { var words = $(this).html().split(" "); for (var i=0; i<words.length; i++) { // add caps to first letter var firstLetter = words[i].substr(0,1).replace(/(\w)/i, '<span class="cap">$1</span>'); words[i] = firstLetter + words[i].substr(1); } return $(this).html(words.join(" ")); }); }
Comments
Subscribe to comments
You need to login to post a comment.

Thanks for this script