4 ms·
Optional chaining is widely supported and solves this problem for single-element queries. qsA returns an empty NodeList when the selector matches no elements, a
by moritzwarhier 2y ago
Optional chaining is widely supported and solves this problem for single-element queries.
qsA returns an empty NodeList when the selector matches no elements, as long as the string is a valid selector. Then forEach doesn't require it anyway.