Computer >> Computer tutorials >  >> Programming >> Javascript

How to change the font color of a text using JavaScript?


To change the font color of a text, use the fontcolor() method. This method causes a string to be displayed in the specified color as if it were in a <font color="color"> tag. 

Example

You can try to run the following code to change the font color of a text using JavaScript −

<html>
   <head>
      <title>JavaScript String fontcolor() Method</title>
   </head>

   <body>
      <script>
         var str = new String("Demo Text");
         document.write(str.fontcolor( "blue" ));
         alert(str.fontcolor( "blue" ));
      </script>
   </body>
</html>