Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

517
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda