0

This is the HTML element which I am trying to replace the text content of:

<h1 id="lastLogin"> </h1>

This is my JS:

if (localStorage.getItem("lastLogin") == undefined) {
  document.getElementById("lastLogin").textContent =
    "Welcome, this is your first time logging in.";
} else {
  document.getElementById("lastLogin").textContent =
    "Welcome, the last time you logged in was on " +
    localStorage.getItem("lastLogin");
}

When I run this I get an Uncaught TypeError: "Cannot set properties of null (setting 'textContent')"

Phil
  • 157,677
  • 23
  • 242
  • 245

0 Answers0