DEV Community

Mario Rodeghiero
Mario Rodeghiero

Posted on • Edited on

4

Automatic CopyRight

File Structure

If someone has doubts about the file structure used, it follows the output of the "tree" command, applied to the computer terminal.

Terminal

HTML code

To display the copyright, I created a file called "index.html" in the root folder (examples-myBlog) and just below the "body" tag, created the "footer" tag and inserted the id = "copy", so let's be able to use the id in our javascript code.
To call our javascript file, we create the "script" tag and insert the src = "js / copy.js".

<html>
  <body>

    <footer id="copy"></footer>

    <script src="js/copy.js"><script>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

JS Code

The first thing to do in the javascript code is to create a new "Date ()" object and store it in the "date" variable. We did this because "Date ()" returns us a very complete information, something like this: "Mon Oct 09 2017 15:27:03 GMT-0300 (-03)". Since we want to display only the year in our copyright, we will create the variable "year" to get only the year of our object, passing "date.getFullYear ()". Now let's just do the basics, we'll get the element with id = "copy" and then use "innerHTML" to display the year on our sample page.

let date = new Date();
let year = date.getFullYear();

let copyRight = document.getElementById('copy');
copyRight.innerHTML = 'Copyright ©'+ year;
Enter fullscreen mode Exit fullscreen mode

This post was first on my blog when I wrote my articles in Portuguese, you can access this link. If you want to follow me on social networks this is my Twitter.

Thanks!!

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (5)

Collapse
 
equinusocio profile image
Mattia Astorino • Edited

It should be a span or not a tag at all. Not a p for sure :)

Collapse
 
mariorodeghiero profile image
Mario Rodeghiero

Thanks for orienting, I changed to span. You spoke, why is it semantically better?

Collapse
 
equinusocio profile image
Mattia Astorino • Edited

Just put the textt inside the footer without any tag OR use the small tag. As html spec says:

Small print typically features disclaimers, caveats, legal restrictions, or copyrights. Small print is also sometimes used for attribution, or for satisfying licensing requirements.

Thread Thread
 
mariorodeghiero profile image
Mario Rodeghiero

Cool...thanks!!

Collapse
 
twistacz profile image
Michal Haták

I never find our why anyone should update copyright. If you do want to have current year in your footer, then you should replace word "Copyright" with "Current Year"

stackoverflow.com/questions/239023...

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay