Error message ".innerHTML is not a function"

JavascriptHtml

Javascript Problem Overview


I'm trying to fill the date automatically in a table header, but all I get is

>".innerHTML is not a function"

I've looked everywhere, and tried put my code at the top and bottom of the page, but nothing works. Help, please!

window.onload = function() {
  var currentTime = new Date();
  var month = currentTime.getMonth() + 1;
  var day = currentTime.getDate();
  var year = currentTime.getFullYear();
  document.getElementById("dated").innerHTML(month + "/" + day + "/" + year);
};

Javascript Solutions


Solution 1 - Javascript

Well, as the error says, innerHTML is not a function.

You can assign a value to the property, though:

document.getElementById("dated").innerHTML = month + "/" + day + "/" + year;

For more infos, have a look at the MDN docs.

Solution 2 - Javascript

innerHTML is a property... thus you need to use = not ()... it's not jQuery.

document.getElementById("dated").innerHTML = "blah"

Solution 3 - Javascript

document.getElementById("dated").innerHTML = month + "/" + day + "/" + year;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEnder CheView Question on Stackoverflow
Solution 1 - JavascriptTimoStaudingerView Answer on Stackoverflow
Solution 2 - JavascriptBenAlabasterView Answer on Stackoverflow
Solution 3 - JavascriptKairatView Answer on Stackoverflow