Simple JQuery Copyright Year script

How many websites do you see that have a copyright line with last year in it?! It’s just a sign of a lazy web developer who can’t be bothered either to update it every year, or (much better) add a simple bit of JQuery to automatically display the current year in the copyright line!

Here’s a code snippet that I use on all my websites to do just that!

In the markup add your copyright statement like this:

&copy; My Company <span id="year"></span>. All rights reserved.

And then add this script to your page (after your JQuery reference):

<script>
  $(function(){
    var theYear = new Date.getFullYear();
    $(“#year”).html(theYear);
  });
</script>

The end result (assuming you’re reading this in 2015…) will look like this:

© My Company 2015. All rights reserved.

Tagged with: ,
6 comments on “Simple JQuery Copyright Year script
  1. Rob Horton says:

    Maff, thanks for writing this. I found it quite handy indeed and really enjoy little snippets like this. I forgot now, how I ran across your blog but I really enjoy your articles. I used the idea from your post for a little post of my own on how to do this with an Angular directive (hope you don’t mind). Keep up the great work!

  2. Frank Jones says:

    Maff, I came across yours and Rob’s posts (great info BTW!) and wanted to share some other information I came across. Apparently, the year displayed is supposed to be the year of first publication (http://www.copyright.gov/circs/circ03.pdf). I personally prefer the updated copyright year, but thought I would share the info.

    • Maff Rigby says:

      Hi Frank,

      Thanks for the link and you’re right that technically the copyright date is from when a piece of content is first published. However, most websites tend to go for the current year.

      I have seen some websites occasionally where they use a date range (e.g. 2012-2015) so maybe that could be an alternative solution?

      Thanks,

      Maff

  3. MarkCanada2015 says:

    Hmmm, I guess even after 15 yrs being a developer, mistakes happen.

    Your script is in error, it does not work and here is why.

    Error >> var theYear = new Date.getFullYear();

    Correct >> var theYear = new Date().getFullYear();

    // forgot to insert the open-close brackets after Date

    Error >> $(β€œ#year”).html(theYear);

    Correct >> $(“#year”).html(theYear); (or ) $(‘#year’).html(theYear);

    //Wrong type of quotes, if I copy and paste from your webpage. Your webpage displays “smart quotes” and jQuery scripts take those as an unacceptable script character.
    //For those who may not see these easily or have trouble changing them in your text editor, just replace the double quotes for single ones ‘ ‘ in this script.

    Now the script works.

    • matt says:

      Correct:

      $(function(){
      var theYear = new Date().getFullYear();
      $(‘#year’).html(theYear);
      });

      thnks mark

1 Pings/Trackbacks for "Simple JQuery Copyright Year script"
  1. […] I thought it a good exercise to take what was written here at Maff Rigby’s website and do me some learnin’ about AngularJS […]