by gmiller123456 · 5y ago · 0 comments
I'm curious as to whether there's a proper use case for querySelectorAll. I always use the getElementsByClassName, getElementById, and getElementsByTagName based on what I want. I find the more general querySelectorAll to be too likely to produce a bug when someone uses a CSS class name that equals a tag or ID. You can make it work, but I find it's too easy to re-use a word in different context, especially if it's different people doing the coding vs CSS.
document.querySelectorAll("[data-my-attr=something]")
document.querySelectorAll(".foo > [data-my-attr=something]")
etc.
Of course if that’s a need the page needs work but, not everything is “fixable” in time limited business cases.