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

516
Views
How can I add DOM support with JSDOM to use functions like document.getElementById() when using NodeJS

Ello!

I am looking to change apart of my inner html using document.getElementById("textToChange").innerHTML.

However, I keep getting this error when I attempt to run my JS file with node filename.js

TypeError: Cannot set properties of null (setting 'innerHTML') at Timeout._onTimeout (C:\Users\Luke.Gebbink\Documents\wallboardgit\JS\sslCert.js:44:58) at listOnTimeout (node:internal/timers:559:17) at processTimers (node:internal/timers:502:7)

I am assuming that the JSDOM global.document is not the actual webpage. How can I make it so that I can run code that refers to my index.html's elements using JSDOM; as it will not without it. Here is my code below.

    const jsdom = require("jsdom");
        const { JSDOM } = jsdom;
        
        const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
 global.document = new JSDOM().window.document;

        console.log(dom.window.document.querySelector("p").textContent); // "This Runs, so I have JSDOM Installed"

        document.getElementById("textToChange").innerHTML = 'TEST' //This does not work
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!