Friday, September 20, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...