How to set the capitalization of a text with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

To set the capitalization, use the textTransform property in JavaScript. Set it to capitalize, if you want the first letter of every word to be a capital letter.

Example

You can try to run the following code to return the capitalization of a text with JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <button onclick = "display()">Capitalize Text</button>

      <div id = "myID">
         This is demo text! This is demo text!
      </div>

      <script>
         function display() {
            document.getElementById("myID").style.textTransform = "capitalize";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 08:08:54

Advertisements