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

Best way for $("#foo .bar") #141

Closed
adrianoresende opened this issue Mar 31, 2017 · 1 comment
Closed

Best way for $("#foo .bar") #141

adrianoresende opened this issue Mar 31, 2017 · 1 comment

Comments

@adrianoresende
Copy link

document.querySelector and document.querySelectorAll are quite SLOW,

What is better way if use $("#foo .bar") ?

1 - document.getElementById('foo').getElementsByClassName('bar') ?

or

2 - document.querySelector('#id .bar') ?

@kaidez
Copy link

kaidez commented Mar 31, 2017

I would say number 2 is better since getElementsByClassName is buggy. But I would also suggest that you avoid selecting things with descendant selectors as it's an anti pattern since it's under-performant.

e.g try and do document.querySelector('#id') or something similar instead of document.querySelector('#id .bar').

@camsong camsong closed this as completed Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants