Java Reference
In-Depth Information
}
el.src = myImages[newImgNumber];
}
function updateStatus(e) {
var el = e.target;
var status = document.getElementById("status");
status.innerHTML = "The image changed to " + el.src;
if (el.src.indexOf("mexico") > -1) {
el.removeEventListener("click", changeImg);
el.removeEventListener("click", updateStatus);
}
}
var imgObj = document.getElementById("img0");
imgObj.addEventListener("click", changeImg);
imgObj.addEventListener("click", updateStatus);
</script>
</body>
</html>
Save the page as ch10_example7.html . Load the page into your browser, and you will see a page with
a single image. Click the image, and it will change to a random picture. You'll also see the text of the
<div/> element change to contain the URL of the new picture, as shown in Figure 10-2.
figure 10-2  
Search WWH ::




Custom Search