Skip to content

querySelectorAll workaround is not always needed #430

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

Closed
wartmanm opened this issue Oct 22, 2018 · 0 comments
Closed

querySelectorAll workaround is not always needed #430

wartmanm opened this issue Oct 22, 2018 · 0 comments
Milestone

Comments

@wartmanm
Copy link
Contributor

If I understand it correctly, the issue with qSA that https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L301 works around is that it matches using the entire document, including the context element's parents. But this should only be relevant if there are child or descendant combinators in the selector. Without them, it shouldn't be possible for the search to ascend above the context element, and so qSA will return the desired results without any special effort.

By skipping the workaround, the potentially expensive setAttribute and removeAttribute calls can be avoided. I would hope that browsers' native qSA machinery would benefit from simpler selectors as well.

I think the types of simple selectors, like div.class.anotherClass, that can benefit from this are relatively common, and checking if a selector qualifies is cheap since it already has to be tokenized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants