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
`)
– CertainPerformance Apr 26 '22 at 01:58