DEV Community

Cover image for JavaScript snippet for dynamically updating footer copyright year.
Vivekanand Padala
Vivekanand Padala

Posted on • Edited on

JavaScript snippet for dynamically updating footer copyright year.

Hi, today am going to code a js snippet for dynamically updating the footer’s copyright year.

document.getElementById('copyrightYear').innerHTML = new Date().getFullYear();
Enter fullscreen mode Exit fullscreen mode

Place the id (copyrightYear) in a span tag at the footer section after © symbol and before company name.

Place the above code in script tags at the bottom before closing body tag.

You will get the current year without any hassle to update it regularly every year.

If you like the post, share with your friends.

Cheers!

Top comments (5)

Collapse
 
jochemstoel profile image
Jochem Stoel

document.write is deprecated.

Collapse
 
vivekanandpadala profile image
Vivekanand Padala

Thank you, edited it. But actually as far I learned no one mentioned that document.write() is deprecated but I think it is a bad practice. Am still a novice in JS. Thank you for pointing it out.

Collapse
 
belinde profile image
Franco Traversaro

Are you a time traveler from the remote past?

Collapse
 
vivekanandpadala profile image
Vivekanand Padala

Good one Franco ;)

Collapse
 
vivekanandpadala profile image
Vivekanand Padala

Excellent.. Am hoping to learn Rails after mastering js and node.