Posted By

nijgnet on 04/01/10


Tagged


Versions (?)

Set first-letter caps to style


 / Published in: jQuery
 

Usage: $(selector).addCaps();

  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
Posted By: raghibsuleman on April 21, 2010

Thanks for this script

You need to login to post a comment.