May 19, 2022
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

When your bath soap bar gets too small to use, don't throw it away! open the next bar, and when you finish showering, stick the small old bar to the back of the new bar. Onces they both dry, they will become one.

Might also interest you:

Scaleable Vanilla JS Nested Tabs

JavaScript
Cloneable
Code

Nested tabs in an accordion template

Read more
Blue arrow iconWhite Arrow icon

Buttons Hover Interactions

Cloneable
Interactions

A small collection of buttons and hover interactions.

Read more
Blue arrow iconWhite Arrow icon

3d Video Slider (swiper.js)

Cloneable
CMS
JavaScript

A 3d slider with video items, plays and pauses on click & slide change.

Read more
Blue arrow iconWhite Arrow icon