Capitalize Words Using JavaScript. This page shows how to capitalize words in a text string using JavaScript (i.e. change the first letter of each word to upper-case). Place the following code in the document head. This contains the capitalize function which does the conversion: String.prototype.capitalize = function(){.