|
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>
|
|
|
Copyright © 1996-2009 irt.org, All Rights Reserved.