Skip to content
Advertisement

How can one create a dynamic copyright date without document.write() in JavaScript?

How can one fetch and print the current year without using document.write() in JavaScript?

This is for a typical copyright line in the footer; e.g., © 2017 Stack Overflow.

Right now I’m using the standard document.write() method.

JavaScript

Advertisement

Answer

Yes sure you can use an element:

JavaScript

Add a link to your JS like so:

JavaScript

And within this file you can do:

JavaScript

Alternatively you can simply use php like so:

JavaScript

If you are using php just make sure you change the file ext to PHP.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement