Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q681 If I have an image object within <DIV> tags, how can I access the image without errors?

irt.org | Knowledge Base | DHTML | Q681 [ previous next ]

Q681 If I have an image object within <DIV> tags, how can I access the image without errors?

If you've turned the <DIV> into a layer, then you'll have to go via the layer first:

<DIV NAME="myDiv" STYLE="position: relative">
<IMG SRC="image.gif" NAME="myImage" WIDTH="100" HEIGHT="100">
</DIV>

<FORM>
<INPUT TYPE="BUTTON" VALUE="Click Me!" onClick="if (document.images) document.layers['myDiv'].document.images['myImage'].src = 'another.gif'">
</FORM>

Instead of:

<DIV>
<IMG SRC="image.gif" NAME="myImage" WIDTH="100" HEIGHT="100">
</DIV>

<FORM>
<INPUT TYPE="BUTTON" VALUE="Click Me!" onClick="if (document.images) document.images['myImage'].src = 'another.gif'">
</FORM>

It is also necessary to test for the support of layers:

<DIV NAME="myDiv" STYLE="position: relative">
<IMG SRC="image.gif" NAME="myImage" WIDTH="100" HEIGHT="100">
</DIV>

<FORM>
<INPUT TYPE="BUTTON" VALUE="Click Me!" onClick="if (document.images) {if (document.layers) document.layers['myDiv'].document.images['myImage'].src = 'another.gif'; else document.images['myImage'].src}">
</FORM>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.