I'm not really a html javascript programmer, so I need some handholding. I found a snip of code that I can plug into my website, but I'd like to add formatting. I'm trying to display the current date (which this does), but I'd also like it to be H1, Bold, and Centered. I've spent several hours trying to figure this out, and thought maybe someone here could set me straight.
Here's the code snip (currently works), how do I format it?
<script type="text/javascript"> var d=new Date(); var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday"); var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); document.write(weekday[d.getDay()] " "); document.write(d.getDate() ". "); document.write(monthname[d.getMonth()] " "); document.write(d.getFullYear());</script>
CodePudding user response:
This is accomplished quite easily with CSS, but note that an h1
should not be used because of the native styling that the browser will render it with. h1
is for document structure. If you want bigger text, just style that as well:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My Page Title</title>
<style>
#date { font-weight:bold; text-align:center; font-size:1.1em; }
</style>
</head>
<body>
<div id="date"></div>
<script>
var d = new Date();
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday"];
var monthname = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
document.getElementById("date").textContent = weekday[d.getDay()] " " monthname[d.getMonth()] " " d.getDate() ", " d.getFullYear();
</script>
</body>
</html>
CodePudding user response:
Just Add the tags you said like <tag>...content...</tag>
<div style="text-align:center">
<h1>
<strong>
<script>
var d = new Date();
var weekday = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var monthname = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
document.write(weekday[d.getDay()] " ");
document.write(d.getDate() ". ");
document.write(monthname[d.getMonth()] " ");
document.write(d.getFullYear());
</script>
<strong>
</h1>
</div>