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:

Share:

The videos Kurzgesagt channel creates are so beautifully animated, that I almost forget that I learn so much while watching them!

Might also interest you:

3d Video Slider (swiper.js)

Cloneable
CMS
JavaScript

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

Read more
White Arrow icon

Webflow Dashboard Workspaces Hack

Webflow UI Hack
Code
CSS

Convert the Workspaces dropdown to an open sidebar with custom order.

Read more
White Arrow icon

Glossary

Cloneable
JavaScript
CMS

A clonable for creating an Alphabetical glossary

Read more
White Arrow icon