Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] replace querySelector with getElementById where possible, cache querySelector calls where posssible and needed #3046

Open
jxn-30 opened this issue May 31, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jxn-30
Copy link
Member

jxn-30 commented May 31, 2024

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!

@jxn-30 jxn-30 added the enhancement New feature or request label May 31, 2024
@jxn-30
Copy link
Member Author

jxn-30 commented Aug 27, 2024

#3162 introduced replacement of querySelector calls with getElementById where possible.
Next step: Check if any querySelector call can be cached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant