DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Mario Rodeghiero
Mario Rodeghiero

Posted on • Updated on

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!!

Top comments (5)

Collapse
 
equinusocio profile image
Mattia Astorino • Edited on

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 on

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...

Classic DEV Post from 2020:

js visualized

πŸš€βš™οΈ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! πŸ₯³

Happy coding!