a simple javascript example

Applying Different Styles in Different Hours of a Day

“Applying Different Styles in Different Hours of a Day” is a simple web page that indicates how to change style in different hours of a day through the use of JavaScript.

DEMO LINK: http://parhammajd.co.uk/examples/css/dayNight.html



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Different Hours Different Styles</title>
<script type="text/javascript">
function setTimedStylesheet() {
var theTime = new Date().getHours();
if (8 <= theTime&&theTime < 20) {
document.write("<style> body { background-color:blue;}</style>");
}
if (20 <= theTime&&theTime < 8) {
document.write("<style> body { background-color:black;}</style>");
}
}
setTimedStylesheet();
</script>
</head>

<body>

</body>
</html>


Leave a Reply

Your email address will not be published. Required fields are marked *