Copyright Snippet
levimcg.com·268w

It’s that time of year again, so I thought I’d do a quick post on the simple bit of JavaScript I use to keep the copyright date current in the static sites I build. Add the hidden attribute to your container element markup so that if JS fails for some reason it won’t display.

class CopyrightElement extends HTMLElement {
connectedCallback() {
this.innerHTML = `© ${new Date().getFullYear()}`;
}
}

if ('customElements' in window) {
window.customElements.define('copyright-element', CopyrightElement);
}

As a bonus, here’s a tiny custom element I made that does the same thing. This way you can just wrap your static text in a `` tag and as long as the browser is capable and you scripts loaded, you get an upgraded, up-to-date footer copyright date.

(function() {
document.add...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help