Javascript Style How to - Add a dynamic style








Question

We would like to know how to add a dynamic style.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.blue {<!--from  w  ww.  j  a v a 2 s.  c o m-->
  background-color: blue;
}
</style>
<script type='text/javascript'>
window.addEvent('load', function() {
    document.body.className = 'blue';
});
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: