I have this simple function that needs to find an element and set its height on load:
function setGround() {
document.getElementById('content').style.height = '40px';
}
document.onload = setGround();
However the function returns “null” on load. Am I missing something obvious? Yes the element with that ID does exist.
Thank you for your help.
Remove the
()or the function runs immediately, and thendocument.onloadis set to the return of the function (which in your case isnullundefined).