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);
};
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.
innerHTML is a property... thus you need to use = not ()... it's not jQuery.
document.getElementById("dated").innerHTML = "blah"
document.getElementById("dated").innerHTML = month + "/" + day + "/" + year;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With