img.href object doesn't support this action

D

Darren

Hi i have this code

var newsTab=document.getElementById("newsTab");
newsTab.href="latestTabClosed.gif";

where "newstab" is an Image placeholder
<img name="newsTab" id="newsTab" src="" width="256" height="32" alt="News
Tab">

In the documents i've read this is the way to dynamically change an image
but all i get is a "Object doesn't support this action" error. Why?

Thanks in advance.
 
A

ASM

Darren said:
Hi i have this code

var newsTab=document.getElementById("newsTab");
newsTab.href="latestTabClosed.gif";

where "newstab" is an Image placeholder
<img name="newsTab" id="newsTab" src="" width="256" height="32" alt="News
Tab">

Try to have not same name for name/id and for JS object
In the documents i've read this is the way to dynamically change an image
but all i get is a "Object doesn't support this action" error. Why?

because :
it is not 'href' but 'src' that calls image file <img SRC="file.jpg">

newsTab.document.getElementById("newsTab");
newsTab.src = "latestTabClosed.gif";
or
newsTab.document.images["newsTab"];
newsTab.src = "latestTabClosed.gif";
or
document.images["newsTab"].src = "latestTabClosed.gif"
or
document.getElementById("newsTab").src = "latestTabClosed.gif";
 
E

Evertjan.

ASM wrote on 31 aug 2005 in comp.lang.javascript:
newsTab.document.getElementById("newsTab");
newsTab.src = "latestTabClosed.gif";

newsTab = document.getElementById("newsTab");
newsTab.src = "latestTabClosed.gif";
or
newsTab.document.images["newsTab"];
newsTab.src = "latestTabClosed.gif";

newsTab = document.images["newsTab"];
newsTab.src = "latestTabClosed.gif";
or
document.images["newsTab"].src = "latestTabClosed.gif"
or
document.getElementById("newsTab").src = "latestTabClosed.gif";
 
D

Darren

ASM said:
Try to have not same name for name/id and for JS object


because :
it is not 'href' but 'src' that calls image file <img SRC="file.jpg">
See that's what i thought but the document i read used href and trying it
with src would have been far too sensible. :)
newsTab.document.getElementById("newsTab");
newsTab.src = "latestTabClosed.gif";
or
newsTab.document.images["newsTab"];
newsTab.src = "latestTabClosed.gif";
or
document.images["newsTab"].src = "latestTabClosed.gif"
or
document.getElementById("newsTab").src = "latestTabClosed.gif";
Well despite the typo in the above i wish all documentors were as thorough
as you. :)
Thanks Stephene
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top