< Back
Javascript Title Case
Tutorial by James of Bandit.co.nz
Copyright James Nisbet 2005 ~ 2007

13th October 2006

In the following tutorial I will explain how to capitalize the first letter in a Javascript string.

It's very simple - simply by grabbing the first letter, capitalizing it, then appending the rest of the string on the end.

var mystr = "hello world!";
mystr = mystr.substr(0,1).toUpperCase()+mystr.substr(1);

As simply as that, mystr will now equal "Hello world!".

It would be very easy to expand this script to capitalize the first letter in each word in a sentence, but I'll leave that up to you!

Have fun! If you have any issues, please drop me a line.

If you liked this tutorial please tell a friend.


< Back

Page dynamically created in 0.001 seconds by morBandit's phpTutorial v28.02.05. 5049 page views.