Friday 20 September 2019

javascript - getElementById() returns null even though the element exists

Your script runs before the DOM has been loaded. To fix this you can place your code in the window.onload function like so:


window.onload = function() {
alert(document.getElementById("abc"));
};

An alternative is to place your script right before the closing tag.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...