Skip to content

Instantly share code, notes, and snippets.

View jjanusch's full-sized avatar

Josh Janusch jjanusch

  • Vincit
  • Phoenix, AZ
View GitHub Profile
@jjanusch
jjanusch / jquery.capitalize.js
Last active August 29, 2015 14:03
Extends jQuery via prototype to capitalize the first letter of each word in a sentence ('all'), just the first word in a sentence (default), or title text ('title' - capitalizes each word in the sentence minus words like "the", "and", "or", "but" etc. Usage included under code.
String.prototype.capitalize = function(type) {
var array, capitalized, doNotCapitalize;
// if type = all, capitalize first letter of each word
if(type === 'all'){
array = this.split(' '); // split on spaces
capitalized = '';
$.each(array, function( index, value ) {
capitalized += value.charAt(0).toUpperCase() + value.slice(1);