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);
};
Solution 1:
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:
innerHTML is a property... thus you need to use = not ()... it's not jQuery.
document.getElementById("dated").innerHTML = "blah"
Solution 3:
document.getElementById("dated").innerHTML = month + "/" + day + "/" + year;