Set first-letter caps to style


/ Published in: jQuery
Save to your folder(s)

Usage: `$(`selector`).addCaps();`


Copy this code and paste it in your HTML
  1. jQuery.fn.addCaps = function() {
  2. this.each(function ()
  3. {
  4. var words = $(this).html().split(" ");
  5. for (var i=0; i<words.length; i++)
  6. {
  7. // add caps to first letter
  8. var firstLetter = words[i].substr(0,1).replace(/(\w)/i, '<span class="cap">$1</span>');
  9. words[i] = firstLetter + words[i].substr(1);
  10. }
  11. return $(this).html(words.join(" "));
  12. });
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.