Stop Using querySelectorAll for Immediate Children. Try This Instead.
Most JavaScript developers default to nested loops or children properties to select immediate child elements. But there’s a cleaner, CSS-native solution: the :scope pseudo-class. By scoping querySelector to a specific element, :scope > .child gives you precise direct-child selection without descendant traversal bugs. This tiny technique mirrors the isolation patterns of CSS Modules and Shadow DOM – and it’s fully supported in modern browsers since 2015.