
Dark Mode is a design trend where the color scheme of a website is changed to a dark background with light-colored text and elements. It's also ref...
For further actions, you may consider blocking this person and/or reporting abuse
What is the general consensus in the community about referencing elements like this? As opposed to:
Isn't it considered unsafe and error-prone? I don't really remember, it's rarely seen in the wild, perhaps for a reason.
When I write example-code for articles, I tend to omit selectors, because I want to focus on what the code does, rather than how to select a Node in the DOM.
I assume most of Dev.to's readers knows how to do that anyway, and might want to use their own selectors (class-based, attribute-based, something else?) instead of just copy/pasting the code.
But I could be wrong! So thank you for your feedback — I've added this to the article:
It's best practice to use
document.getElementById
over the global variable because defining a local variablecolorScheme
would take precedence. It's also annoying to debug these global variables because they are not explicitly defined. When searching for something likecolorScheme =
you won't find anything, and finding something likecolorScheme.addEventListener
tells you nothing about the type of variable. However, findingdocument.getElementById
tells you it's a DOM element.I vote that implicit code is dangerous code and explicit code is safe code and there is no grey area 🫣
(see updated feedback above)
Very detailed post! Great share! @madsstoumann Framing these screenshots would've been chef's kiss. I've built a simple OSS tool to help with screenshots with ease. Give it a shot and let me know what you think.
github.com/ekqt/screenshot
Cool!
Very cool.
I've used this scheme of system themed colours when programming Windows desktop apps.
I didn't know it existed in CSS though - thanks!
👍🏻
I love it.
👍🏻
Love this ❤️, Thanks for sharing.
👍🏻
This is something I'm for, Thanks for sharing! 🚀
👍🏻
Great tips, this was exactly what I've been looking for! 👏
👍🏻
Amazing code snippet.. thanks for telling.
You just saved a lot of time ⏲️ 😌
👍🏻
If statement missing here:
A notice that the article refers exclusively to the latest version of Chrome should be included at the very beginning.
??? System colors work in all browsers
Just test your code in all browsers and you'll get bad news. The browser war is still here.