I'm using the following code to (try to) update the style of an element in javascript. As you'll no doubt gather from the code, I'm trying to edit the opacity of the element.

This code executes fine in FF, Opera and Chrome. However, Internet explorer keeps responding with 'style is null or not an object'. Basically, I don't think it's returning the correct element from the DOM, or, for that matter, any element.

To add some more specific guidance, on the homepage I call launch_randomise() in the onload method, which, after 5 seconds, calls randomise_bottom_images() which calls itself and the bottom image regeneration function every 5 seconds, ensuring the images are regenerated every five seconds.

Regenerating the bottom images is a three-step process: 1, fade out, 2 switch innerHTML, 3, fade back in. My functions for altering the opacity or innerHTML quite obviously rely on being able to talk about a DOM object, I know no other way of achieving this. I tried straight out getElementById but this doesn't seem to work in IE8, fine in FF, Op, GC.

So, after much googling I replaced getElementById(string) with my own getElement(string). However, this still doesn't work.

// Preserve any properties we care about (id and class in this example)
newEl.id = oldEl.id;
newEl.className = oldEl.className;
//alert(newEl.id);
//set the new HTML and insert back into the DOM
newEl.innerHTML = html;

I tried element.opacity = x in the onload function and hey presto it worked just like that.

Which led me to think; what's wrong with my code, then? Well, everywhere I've used pseudo functions (inline functions, whatever they're called), from that point forward including any subsequent function calls ( so if I define function(a){call something} inline) the DOM is inaccessible.

But only in IE.

glenngv

12-06-2009, 08:52 AM

You're also doing MozOpacity and KhtmlOpacity which IE does not support.