Link to home
Avatar of supportoranges
supportorangesFlag for United States of America

asked on

How can I reference this element using document in Javascript

I need to dynamically change the src attribute (see snippet below).  Please tell me how can I reference this using document in Javascript.  I have limited Javascript exp.

<td width="150" height="198"><img border=0 width=150 height=76 src=http://ep.yimg.com/ca/I/yhst-123908713209812348></td>
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Can you modify the html? If the img tag had an id attribute, you could reference it by its id. For example:

<img id=myimage" border="0" width="150" height="76" src="http://ep.yimg.com/ca/I/yhst-123908713209812348">

Open in new window

could be referenced in javascript by:

document.getElementById("myimage").src = "http://newurl";

Open in new window

Avatar of supportoranges

ASKER

I cannot add id attribute on the img tag but i can add it on the <td>

THIS IS POSSIBLE:
 <td id="cellContainingImage" width="150" height="198"><img border=0 width=150 height=76 src=http://ep.yimg.com/ca/I/yhst-1234567890></td>

The reason I can't add id attribute on img tag is because html for <img> tag is generated using Yahoo store tag.
ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
That will work - lovely!
Thank you, that was very helpful