White Arrow icon
Back to all Elements

Auto get Current Year

Automatically insert the current year to any element with the class of 'year'

We start by creating a variable that contains all the elements with the classname of 'year'

Then we go through each one and change its 'Inner HTML' to the text of the 'full current year' (eg. 2022).

The code can be pasted on any page's 'Before </body> tag' or on the site's settings 'Footer code'.

<script>
 var yearElements = document.getElementsByClassName( 'year' );

 [].slice.call(yearElements).forEach(function (div) {
   div.innerHTML = new Date().getFullYear();
 });

</script>

Copy

Preview:

browser mockup
Share:
Heart icon

A tongue scraper is is so much better in cleaning your tongue instead of the normal brushing it.

Might also interest you:

CMS Autocomplete

Cloneable
CMS
JavaScript

A short JavaScript code for transferring a CMS list into an autocomplete on an input field.

Read more
Blue arrow iconWhite Arrow icon

Scroll Menu to Current Link

Cloneable
CMS
Code

Using JS to scroll a div (menu) to the current link inside.

Read more
Blue arrow iconWhite Arrow icon

Background Video with Audio (using plyr.js)

Cloneable
Code
JavaScript

An embed video with Mute/UnMute button using plyr.js plugin.

Read more
Blue arrow iconWhite Arrow icon