joedborg
joedborg

Reputation: 18343

IE error with javascript that works fine on Firefox and Chrome

document.getElementById("displayImage").getElementsByTagName("img")[0].src = "image2.png"

I seem to remember that for IE, you need to add a <meta> tag of some description, but I can't find which one.

If it helps:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0;

Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR

3.5.30729; .NET CLR 3.0.30729) Timestamp: Tue, 6 Sep 2011 12:23:00 UTC

Message: Object doesn't support this property or method

Upvotes: 0

Views: 171

Answers (2)

Jeremy
Jeremy

Reputation: 792

As I mentioned in a comment above, the code is fine; there's no need for a meta tag. I suspect there is some other JavaScript error occurring before the code executes. It's either that, or the elements don't exist in the document when the code executes.

Upvotes: 1

Mars
Mars

Reputation: 4307

try setting the src attribute for the image like this

var image = document.getElementById("displayImage").getElementsByTagName("img")[0];
image.setAttribute("src",path);

Upvotes: 0

Related Questions