/ Published in: jQuery

Usage: `$(`selector`).addCaps();`
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
