I have searched over the web can can\'t find anything to help me. I want to make the first letter of each word upper case within a variable.
So far i have tried:
Building on @peter-olson's answer, I took a more object oriented approach without jQuery:
String.prototype.ucwords = function() {
return this.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
}
alert("hello world".ucwords()); //Displays "Hello World"
Example: http://jsfiddle.net/LzaYH/1/