The copyright text is an essential and must-have element in the footer section of the webpage. The year used in the copyright notice text must be updated with the current year. It is a very hectic task to update copyright year text each year. It’s always recommended for developers to use dynamic year in the copyright section so that the year can be changed automatically and updated with the current year.
Define an HTML element where the dynamic year will be attached to be updated with the current year.
<p>© <span id="copyrightYear"></span> by ZRTECH. All rights reserved.</p>
Here’s the magic formula, ready to be woven into your web pages:
document.getElementById("copyrightYear").textContent = new Date().getFullYear();
Use code with caution. Learn morecontent_copy
Decode this spellbinding code:
- Target Element:
document.getElementById("copyrightYear")pinpoints the element on your page where you desire the dynamic year to appear.
- Timely Summoning:
new Date().getFullYear()conjures the current year directly from the user’s system clock.
- Yearly Renewal:
textContentgracefully assigns the retrieved year to the designated element, ensuring continuous accuracy.
Unlock a Realm of Benefits:
- Effortless Maintenance: No more manual updates, even as time marches forward.
- Enhanced User Experience: Visitors witness a meticulous attention to detail, fostering trust.
- SEO Friendliness: Search engines adore websites that feel alive and up-to-date.