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

428
Views
How can I add a css class to an element with Puppeteer

tried code below returned Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'add'). The class 'form-control' is on all inputs

const forms = ".form-control";
if (device.name === "Panel") {
    await page.evaluate((s) => {
        let dom = document.querySelectorAll(s);
        dom.classList.add("_has_error");
    }, forms);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

querySelectorAll returns an array of elements. You can try dom.classList is undefined indeed as the error says, but dom[0].classList gives valid DOM token list.

You need to iterate over the dom array, e.g. with Array.forEach() if you want to apply your class on every matching elements:

let dom = document.querySelectorAll(s);
dom.forEach(el => el.classList.add("_has_error"));
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!