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

Whenever possible, use Class Names to target the elements in your interaction. You never know when you'll need to duplicate and use it somewhere else...

Might also interest you:

Webflow Dashboard Workspaces Hack

Webflow UI Hack
Code
CSS

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

Read more
Blue arrow iconWhite Arrow icon

Glossary

Cloneable
JavaScript
CMS

A clonable for creating an Alphabetical glossary

Read more
Blue arrow iconWhite Arrow icon

Dynamic Height

Code
Tricks
JavaScript

A (custom code) solution that combines CSS variables and Vanilla JavaScript for the shrinking / growing of browser top & bottom bars.

Read more
Blue arrow iconWhite Arrow icon