<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="Samples2.css">
<title>jQuery with HTML and CSS</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
var the_timeout;
function writeTime()
{
//get a Date object
var today = new Date();
//get some info from the Date object
var hours = today.getHours();
var AMPM;
if (hours <= 11 && hours > 0)
{
AMPM = "AM";
}
else if (hours == 0)
{
hours = 12;
AMPM = "AM";
}
else if (hours == 12)
{
AMPM = "PM";
}
else
{
AMPM = "PM";
hours -= 12;
}
var minutes = today.getMinutes();
var seconds = today.getSeconds();
//make the minutes and seconds look right
minutes = fixTime(minutes);
seconds = fixTime(seconds);
//put the time string together and display it
var the_time = hours + ":" + minutes + ":" + seconds + " " + AMPM;
/*****
*
* Put some jQuery code here, which puts/displays the contents of the_time
* in the div with the id of "newContentsDiv". Include (add) some <p> ... </p>
* tags around the_time.
*
******/
//run this function again in 1 second
the_timeout = setTimeout("writeTime();", 1000);
}
function fixTime(the_time)
{
if (the_time < 10)
{
the_time = "0" + the_time;
}
return the_time;
}
/* ]]> */
</script>
<style type="text/css">
body
{
font-family: Arial,sans-serif;
}
</style>
</head>
<body onload="writeTime();">
<div id="mainDiv">
<h2>The current time is:</h2>
<div id="newContentsDiv">
<p>
(The time goes here.)
</p>
</div>
</div>
</body>
</html>
body {
font-family: Arial, sans-serif;
font-size: 1.3em;
}
#mainDiv {
width: 600px;
border: 1px solid gray;
border-radius: 20px;
padding: 20px;
margin: 0 auto;
}
.attention {
font-weight: bold;
color: #F00;
}
#newContentsDiv {
border: 1px solid gray;
border-radius: 10px;
margin: 20px;
padding: 10px;
}
p {
color: #3C3;
}