When my document loads, I’d like to have JavaScript reload my images’ sources. To do so, I got the following code in my HTML document:
<img src="#" id="mypic" onload="reloadImage(this);"/>
and in my JavaScript document:
function reloadImage(imageElement) {
imageElement.src = "http://www.somedomain.com/image.png";
}
However, this doesn’t work. Am I using this incorrectly, or does the problem lie elsewhere?
The syntax you use is correct in principle. The problem is that for the URL
#, being an invalid image URL, theloadevent is probably never fired.