Re: IE can't access image src
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Fri, 28 Dec 2007 17:13:13 -0800 (PST)
On Dec 28, 7:51 pm, faraz_mit <Faraz...@xxxxxxxxx> wrote:
Hi
I posted the same issue but since I was using the old syntax of
"document.all", I took the focus away from the actual problem. I am
trying to change the image source on a click event but can't access
the image src using Internet explorer. Same code works fine in Firefox
and alerts the correct image src but I get undefined in Internet
explorer. I am using IE version 6.
I also tried document.images['im'], document.getElementById['im'], and
That second one is nonsense. Use:
document.getElementById('im')
(presuming that the image element has an ID of "im.")
document['images']['im'] but none of them worked.
That is the same as document.images['im'] or document.images.im, which
will retrieve the image if it has that name. IIRC, in some browsers,
it will retrieve an image with an ID of 'im', but only if there is no
contradictory name attribute.
Here is the code I have:
/* in the head section I have the following simple javascript function
*/
function changeimgsrc(img_src) {
alert(document.getElementById('im').src);
document.getElementById('im').src = img_src;
Since you used an ID attribute and no name, this would be your best
bet.
}
/* in the body section I have the following nested div structure */
<div id="horizontal_container" >
<h3 class="horizontal_accordion_toggle">...</h3>
<div id="m1" class="horizontal_accordion_content">
<div id="m2" ><img id="im" width="360" src="images/
com_01_angle.gif" /></div>
It isn't the cause of the problem, but get rid of that slash at the
end of the img tag (unless you plan to serve this as XHTML.)
....
<div ><a href="#"
onclick="changeimgsrc('cum_01_angel_blue.gif');">test</a> </div>
......
Do you have an element with a name attribute of "im" elsewhere on the
page? IE will retrieve elements by name with getElementById.
.
- References:
- IE can't access image src
- From: faraz_mit
- IE can't access image src
- Prev by Date: Re: IE can't access image src
- Next by Date: Re: IE can't access image src
- Previous by thread: Re: IE can't access image src
- Next by thread: Re: IE can't access image src
- Index(es):
Relevant Pages
|