DOM query inside a loop body
Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.
What it detects
document.querySelector/querySelectorAll/getElementById/etc. is called inside a loop body, so the browser re-searches the DOM tree on every iteration instead of once. Heuristic: it cannot tell whether the loop runs a handful of times (harmless) or over a large collection (real jank). Hoist the query above the loop when the target does not change per iteration.
Why it matters
Calling document.querySelector/querySelectorAll/getElementById/etc. inside a loop makes the browser search the DOM tree again on every single iteration, instead of once. On a large list or a large DOM this repeated searching becomes visible jank, especially if it also triggers a layout recalculation. This detector cannot tell whether the loop runs a handful of times (harmless) or over a large collection (real cost), so treat it as a prompt to check the loop's expected size.
How to fix it
If the query target does not change between iterations, move the query above the loop and reuse the result inside it. If different elements are queried per iteration, query once for a common ancestor/container and use element-scoped lookups or cached references instead of re-querying the whole document each time.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo