jQuery Data Type How to - Capitalize the first letter of string








Question

We would like to know how to capitalize the first letter of string.

Answer


<!DOCTYPE html>
<html>
<head>
<script>
function ConvertFirstCharacterToUpperCase(text) {
    return text.substr(0, 1).toUpperCase() + text.substr(1);    
}<!--  w  w  w. j  a v  a2  s  .  c om-->
document.writeln(ConvertFirstCharacterToUpperCase("this is text"));

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: