ในการเปลี่ยนสีฟอนต์ของข้อความ ให้ใช้เมธอด fontcolor() เมธอดนี้ทำให้สตริงแสดงในสีที่ระบุเหมือนกับว่าอยู่ในแท็ก
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเปลี่ยนสีแบบอักษรของข้อความโดยใช้ 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>