Javascript Style How to - Change header color








Question

We would like to know how to change header color.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--   ww  w. java 2 s. c om-->
    var header = document.getElementsByClassName("alg");
    header[0].style.color = 'red';
}
</script>
</head>
<body>
  <header class="alg">Some text</header>
</body>
</html>

The code above is rendered as follows: