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

127
Views
Quick javascript to audit for duplicate ids in page DOM

I've found that there are a number of duplicate IDs in the project I'm working on. I don't want to scrape through the entire product all at once, or use on overly heavyweight solution like a full HTML validator - I just want a quick script I can run on any given page to easily identify any duplicate IDs present while I'm working there.

I've found a question along these lines, but it's very old and requests a jQuery solution - we don't use jQuery in this project and it's frankly pretty out of date.

So: what's a little ES6 snippet I can run in the console to identify duplicate IDs in the DOM?

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

0

In modern JavasScript (ES6+), without jQuery:

[...document.querySelectorAll('[id]')].forEach(el => {
  const dups = document.querySelectorAll(`[id="${el.id}"]`);

  if (dups.length > 1 && dups[0] === el) {
    console.error(`Duplicate IDs #${el.id}`, ...dups);
  }
});

All credit to @Rafi: https://stackoverflow.com/a/62145753/1033203

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!