Javascript Style How to - Set text color








Question

We would like to know how to set text color.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!-- w  w w.  j av a  2 s.  c o m-->
<body>
  <span id="test">test</span>
  <script type='text/javascript'>
    var test = document.getElementById('test');
    test.style.color = 'red'
    </script>
</body>
</html>

The code above is rendered as follows: