Home > Back-end >  Why am I getting Null when I want to get a String from an HTML with JavaScript
Why am I getting Null when I want to get a String from an HTML with JavaScript

Time:06-27

I'm trying to build a memento mori kind of clock, and I want to make it so people can insert a certain date in there.

But when I get the element by ID in JS I get null.

Tried to get make it a string and test it with alerts, but I got no results. It was still null.

I mean, the alert box is empty, so I assume it is null.

Some of my assumptions are:

  1. There's a problem with the id or with the document.getElementById("targetDate").innerHTM part
    • I tried to get it as a string and then convert it to date as I did initially using this: new Date("Jan 5, 2090 15:37:25").getTime()
  2. I don't use the date functions the right way
  3. Maybe the approach should be changed to getting the day, month, year & hours separately

Here's the code:

HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>           
  • Related