When scripts are retrieved and evaluated through Ajax, DomReady event
fires immediately (since document is already loaded), so the code
within <script> tags run even though new elements aren't available
yet. That's why $$('#tabs li a').length returns 0.
What you need is a custom event instead of domready, and that you will
fire when onComplete of your request is fired. So you could do the
following:
in "c.php":
window.addEvent('c_php_domready', function() {
/*
Code manipulating elements sent in the same response
*/
// Don't forget to remove the event after use, so making the same
request
// more than once won't trigger multiple instances of the same event!
window.removeEvents('c_php_domready');
});
and in "a.php":
var ajax = new Request.HTML({
url: 'c.php',
/* ... */
onComplete: function(responseTree,
responseElements,
responseHTML,
responseJavaScript) {
$('contentLoad').set('html',responseHTML);
window.fireEvent('c_php_domready');
}
/* ... */
});
This is just an idea tossed like that, but it's tested on IE7, Firefox
2 & 3, Safari 3 and Opera 9. The only downside is that events must be
pretty unique (if you make requests on more than one file), and known
to the code making the request.
I'm not sure if there's a known pattern for loading elements AND
scripts at the same time. In any case, if you still can't get it to
work you may have to load elements and the code manipulating it
separately.
> I have prepared for you a little example of my problem.
http://www.se7en.it/download/moo.zip