Rule proposal: `no-query-selector-all-zero`
See original GitHub issueAvoid selecting an entire NodeList
when only the first item is desired.
Fail
document.querySelectorAll("form")[0].addEventListener("submit", submitFunction);
Pass
document.querySelector("form").addEventListener("submit", submitFunction);
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:11 (9 by maintainers)
Top Results From Across the Web
document.querySelectorAll() function not working on all ...
querySelectorAll returns a collection of elements. The DOM doesn't have a "set-based" feature letting you assign handlers to the entire set ...
Read more >Document.querySelectorAll() - Web APIs | MDN
The Document method querySelectorAll() returns a static (not live) NodeList ... its length property is 0), then no matches were found.
Read more >Is there any analogue to querySelectorAll in SAPUI5?
What I need to do is to select a number of controls by class and add addEventDelegate method to each of them. Is...
Read more >Selectors Level 3 - W3C
A Proposed Recommendation is a document that has been widely ... (When the selectors are not grouped, only the rule for h2..foo is...
Read more >Styling local DOM - Polymer Project
Polymer uses Shadow DOM styling rules for providing scoped styling of the ... 1.6.0 and later accepts @apply without parenthesis, matching the proposal....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another fail:
I’m not sure you’d want to venture into validating CSS selectors, but if you do, this would probably deserve its own rule or even its own plugin.