on Jul 27th, 2008Javascript - Capitalize Each Word in a String

This is a great little function that I use to capitalize every word in a string.

function wordToUpper(str_sentence)
{
    return str_sentence.toLowerCase().replace(/\b[a-z]/g, convertToUpper);

    function convertToUpper()
    {
        return arguments[0].toUpperCase();
    }
}
Bookmark This

Trackback URI | Comments RSS

Leave a Reply

Are you Human?