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:

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:

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