BLUE
Profile banner
AA
Adam Argyle
@nerdy.dev
#CSS DevRel @ Google on Chrome, @ CSSWG, co-host The CSS Podcast, host @ GUI Challenges, co-host the Bad@CSS Podcast. Creator of VisBug, open-props.style, gradient.style, transition.style & more UI, UX, CSS, HTML, JS nerdy.dev
1.9k followers227 following628 posts
AAnerdy.dev

// html <button id="yo">…</button> // js yo.onclick = … No document.querySelector() needed, element ID's are on the window object. #oldie

7

AFaftd.bsky.social

Wait, what happens if you set an id to a value already in use? Does id="undefined" do very terrible things?

2
WBcodersblock.com

ID'd elements go directly into the global namespace? I never knew this! I feel both enlightened and a bit alarmed.

0
YLylynfatt.bsky.social

Did not know this. 🤯

0
Ffrncs.eu

I discovered this totaly by accident while toying with with scripts loading (basic idea was to prevent scripts injected via js from loading twice by assigning an id to the script and checking for its existence instead of relying on external state) and YES, it's awesome and also YES, it's terrible 🤣

0
Rsixsixsix.dev

Say what??

0
JSjschof.bsky.social

Ah yes, one of my javascript guilty pleasures...

1
Aandycouch.com

Wait... I've been writing JS for as long as it's existed and I never knew this tip. I've always used document.getElementById() to access DOM elements with IDs. I'm flabbergasted. Thanks for sharing!

1
Profile banner
AA
Adam Argyle
@nerdy.dev
#CSS DevRel @ Google on Chrome, @ CSSWG, co-host The CSS Podcast, host @ GUI Challenges, co-host the Bad@CSS Podcast. Creator of VisBug, open-props.style, gradient.style, transition.style & more UI, UX, CSS, HTML, JS nerdy.dev
1.9k followers227 following628 posts