I am going to show you how you can create a custom method to capitalize the first letter of each word by using String prototype.
However, you can achieve the same results by using CSS, all you need to do is create a class
.capitalize{
text-transform: capitalize;
}
Despite the fact that it is possible with CSS but sometimes on certain scenarios we need to do this by JavaScript.
See the Pen First letter capitalized of each word with pure JavaScript – simple and easy by Tayab Raza (@TayabRaza) on CodePen.