Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

How do I make the first letter of a string uppercase in JavaScript?

How do I make the first character of a string uppercase if it's a letter, but not change the case of any of the other letters?

For example:

  • "this is a test""This is a test"
  • "the Eiffel Tower""The Eiffel Tower"
  • "/index.html""/index.html"

Answer*

Draft saved
Draft discarded
Cancel
15
  • 30
    @Simon It's not stated that the string is necessarily going to be output as part of a HTML document - CSS is only going to be of use if it is. Commented Jan 18, 2012 at 9:32
  • 10
    Adam, true, but I'd guess that over 95% of the Javascript out there is used with HTML & CSS. Unfortunately, the "capitalize" statement actually capitalizes every word, so you'd still need JS to capitalize only the first letter of the string. Commented Jan 21, 2012 at 4:24
  • 19
    Incorrect, Dinesh. He said the first character of the string. Commented Jun 26, 2012 at 0:02
  • 86
    This answer, despite having a ridiculous number of upvotes, is just wrong, as it will capitalize the first letter of every word. @Ryan, you'll earn a Disciplined badge if you delete it. Please do so. Commented Nov 7, 2012 at 6:06
  • 6
    It's now javascript: $('.capitalize').css('text-transform', 'capitalize') Commented Apr 13, 2013 at 8:58

lang-js

AltStyle によって変換されたページ (->オリジナル) /