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

227
Views
document.querySelector() doesn't work by className - but works by ID and with GetElementsByClassName()

I'm working on an chrome extension that will optimize some of the Gerrit views in our system. As part of the extension I need to get all the elements with a certain class, say, "gerritBody". When inspecting the page this is what I get: Gerrit Inspection Here's what I tried:

var elems = document.querySelectorAll('#gerrit_body'); // works
var elems = document.querySelectorAll('div#gerrit_body'); // works
var elems = document.getElementsByClassName("gerritBody"); // works (*)
var elems = document.querySelectorAll('.gerritBody'); // doesn't work
var elems = document.querySelectorAll('div.gerritBody'); // doesn't work
var elems = document.querySelectorAll('div#gerrit_body.gerritBody'); // doesn't work

(*) I was okay with using getElementsByClassName(), but for some reason despite me seeing the contents of the returned HTMLCollection, I can't access the elements themselves (elems[0] returns 'undefined').

I tried looking it up but everything I found was about CSS selectors, which I believe I used correctly. I also tried all options with both single and double quotes (I'm really new to JS so no idea if it actually matters).

I would be thankful for any direction on how to debug this - as I mentioned, I'm quite new to it, so I'm at loss right now. Thank you!

about 4 years ago · Juan Pablo Isaza
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!