this post was submitted on 21 Jan 2026
372 points (99.2% liked)

Programmer Humor

28669 readers
1851 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] bleistift2@sopuli.xyz 21 points 2 days ago* (last edited 2 days ago) (3 children)

If your element has an id, you can just reference it from the window scope. The const page = is useless. Also the body has its own reference under document: document.body replaces document.querySelector('body')

[–] dan@upvote.au 38 points 2 days ago* (last edited 2 days ago) (2 children)

If your element has an id, you can just reference it from the window scope

This is brittle, as defining a global variable with the same name (or the browser adding a API with the same name) will override it. This functionality was only kept for backwards compatibility with sites designed for Internet Explorer. The spec says to use getElementById instead.

[–] bleistift2@sopuli.xyz 15 points 2 days ago

Aww man. I only found out about this recently :(

[–] bestelbus22@lemmy.world 7 points 2 days ago

I knew about this feature yeah but it seemed too janky to me (which says something, you should see the rest of my project :P)