Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
Is getElementById or getElementsByClassName[0] faster?

Is it faster to use getElementById

document.getElementById('foo').style.visibility = 'visible';

or getElementByClassName[0]

document.getElementsByClassName('foo')[0].style.visibility = 'visible';

I have read that too many IDs can hamper performance, which is why I am trying to shy away from IDs. But if it is faster to use an ID for a quick JavaScript lookup, I will gladly do so.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

getElementById would be the fastest method, since it's simple table lookup.

getElementsByClassName the same as querySelector almost twice as slow.

For best performance use ids for javascript and classes for CSS.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!