I'm loading html content via ajax onto a div (using mootools 1.11 and squeezebox, if it matters).
In the content that I load I have some JS that manipulates some of the loaded HTML objects.
Everything works fine in FF, but when I load it in IE (tested on IE7 for now) the code fails with "'null' is null or not an object.
A quick test shows that the new elements loaded by AJAX are not in the IE DOM. Loaded a div with id 'test' and when I ran document.getElementById('test') I got null. Needless to say running getElementById on original elements works fine.
Does anyone know how to solve / work around this problem?
Some more information: I put my code inside the window 'domready'. Tried using 'load' event, but then IE never called it.
UPDATE
as advised, I checked the same script on IE8 with it's better debugging abilities.
It seems that the problem is indeed in the timing. I run my code at the windows's domReady, and it seems to run instantly, without really waiting for the DOM to be ready (in the popup window). Running the same script using the debugger, once the whole page has loaded, locates the elements with no problem.
So I guess the question now is how to make the script run at the proper time.
- domready event seems to fire well before the dom is ready
- load event seems not to fire at all
- putting the script at the end of the file, after the HTML objects, doesn't help as well
- In the Mootools AJAX options, I indicate 'evalScripts' as true, otherwise the script doesn't run at all
any ideas?