Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error message ".innerHTML is not a function" [duplicate]

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);
};
like image 648
Ender Che Avatar asked Jun 21 '16 18:06

Ender Che


3 Answers

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.

like image 142
TimoStaudinger Avatar answered Nov 16 '22 12:11

TimoStaudinger


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

document.getElementById("dated").innerHTML = "blah"
like image 27
BenAlabaster Avatar answered Nov 16 '22 11:11

BenAlabaster


document.getElementById("dated").innerHTML = month + "/" + day + "/" + year;
like image 26
Kairat Avatar answered Nov 16 '22 12:11

Kairat