document.querySelectorAll('a').forEach(tag => {
// operate on tag
}) document.querySelectorAll('a').forEach(tag => {
// operate on tag
})This is something every web dev will instantly know what it does:
document.querySelectorAll('#rabbit .green').forEach(tag => {
})
Whereas this is something nobody knows what the fuck it is because it's completely non-standard. for (const rabbit of dqsA('#rabbits .green')) {
}
And get what, 10 characters less in one row? Basically nothing.All they did was alias `dqsA`. If anything, it's the fn name that could be better.
Most IDEs will allow you to see what dqsA aliases by mousing over. I don’t really see a problem with it.
It also looks like the kind of thing a pre-commit hook could trivially expand if you’re working with other people who might find it in some way unacceptable.
[...document.querySelectorAll('a')]
.filter(node => node.getAttribute("data-foo") === "bar")Not sure why it caught on.
Might also have something to do with Redux and immutable patterns. (the use of spread operator in general)
and you can querySelectorAll('...').filter(el => ...) without any copies.
and you can querySelectorAll('...').filter(el => ...) without any copies.
ditto for other mentioned functions. Prototypal nature of Javascript is there for a reason.
A lot of people don't have control over the content of their site in enterprise situations. If you're stuck using an old framework or CMS you could be beholden to someone else. And at the same time there's a lot of devs who dgaf and just ship what works.
"#some_combo:has(option:selected[value=..]) + .." seems like a reasonable way to conditionally target something to me, is it terribly worse than some other way?
Yeah, it's fragile and will easily lead to bugs when someone changes the markup without realizing it's going to break some crazy selector in another part of the code.
It would make a lot more sense to just add a class to the element you're trying to select.
Look, if you need this for some one off thing and you've determined it's the best way to do it in this special case, it's not hard to create a function that will find the element you want.
It's not a good argument for using jQuery IMO, because if you're doing this regularly there's probably a better way to do it.
But coming soon™ you will be able to do even this with `document.querySelector`.
Edit: I didn't pay close attention to your second example. I was speaking mostly related to the a:has example before. Your second example seems to be something that would be desired more in CSS than JS, and I don't think it's unreasonable to do that in CSS. If you need to do it in JS you can workaround browser limitations just fine by writing more than one line of code to do the selection and test the condition.
https://developer.mozilla.org/en-US/docs/Web/XPath/Introduct...