File Structure
If someone has doubts about the file structure used, it follows the output of the "tree" command, applied to the computer 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>
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;
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)
It should be a span or not a tag at all. Not a p for sure :)
Thanks for orienting, I changed to span. You spoke, why is it semantically better?
Just put the textt inside the footer without any tag OR use the small tag. As html spec says:
Cool...thanks!!
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...