Pointers to objects

All those references to document.images["image1"] clutter the source up, but there is a shorter alternative. In Internet Explorer it's easy - just use the <img> tag's name= attribute directly, for example:

img1.changePic("pic1.jpg")'

This isn't allowed in Netscape, but instead you can create a pointer to the image object, and use that. It works in IE too, so is cross-browser compatible. Here's the pointer creation statement:

myImg = document.images["img1"]

now you can refer to the object simply as myImg. Here's an example:

<input type="button" value="Picture 1" onclick='myImg.changePic("pic1.jpg")'>

Like the method pointer in the previous page, an pointer to a tag object can only be created after the tag has been rendered by the browser. This means that the creation statement has to be in a function called from the <body> tag's onload= statement (as in this page), or in an inline script at the end of the <body> section.