DOM-Operations and querySelector are heavy operations. getElementById is much faster than querySelector('#id'), especially if called often (e.g. in loops and intervals).
If multiple operations need to be done on an element, avoid selecting the element multiple times but cache it (store it in a variable or in an object) instead.
ESLint Rule unicorn/prefer-query-selector needs to be explicitely be disabled therefore.
An ESLint Rule enforcing us to prefer getElementById wherever possible would be good!
DOM-Operations and
querySelectorare heavy operations.getElementByIdis much faster thanquerySelector('#id'), especially if called often (e.g. in loops and intervals).If multiple operations need to be done on an element, avoid selecting the element multiple times but cache it (store it in a variable or in an object) instead.
ESLint Rule
unicorn/prefer-query-selectorneeds to be explicitely be disabled therefore.An ESLint Rule enforcing us to prefer
getElementByIdwherever possible would be good!