Best Way to Automatically Update Copyright Date with JavaScript

The best way to automatically update the copyright date with JavaScript is to use the Date object to get the current year and then use the innerHTML property to insert the current year into the page.

Here is an example:

Copyright © <span id="copyright-year">2022</span> <script> document.getElementById("copyright-year").innerHTML = new Date().getFullYear(); </script>
Code language: HTML, XML (xml)

This code will insert the current year after the copyright symbol. This will automatically update the copyright year whenever the page is loaded, so you don’t have to worry about manually updating it in the future.

Demo

Copyright © 2022

Posted

in

by

Tags:

Comments

Leave a Reply

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