Created
October 31, 2014 17:33
-
-
Save kidsil/e1a47a289e0d7c2b8c91 to your computer and use it in GitHub Desktop.
To Title Case function on JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toTitleCase = function() { | |
return this.replace(/\b\w+/g, function( str ) { | |
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase(); | |
}); | |
jQuery(document).ready(function(){ | |
jQuery( SELECTOR ).text( function( i, text ) { return text.toTitleCase() } ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment