I have a collection of images in a gallery and I want to assign a class name to all image tags, so that before they finish loading they show a preload.gif. Once the image finishes loading, it should display the actual image. I attempted to achieve this using the following code:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
alert("Image loaded: " + document.getElementsById("myImg").complete);
}
</script>
</head>
<body onload="myFunction()">
<p>This property returns true if the image is finished loading, and false if not.</p>
<img class="myImg" src="compman.gif" alt="Computerman" width="107" height="98">
</body>
</html>
This code only supports the use of id names, but I would like to assign a class name to all image tags instead.