Phillip B Oldham schrieb:
> Hi all
>
> I need to fire an event/run a method once an element (in this case a div
> with a list inside) has loaded, but before $(document).ready().
>
> I'd like to be able to use simple jQuery objects... something like:
>
> $('#mydiv').hasloaded(function(){
> //do something here
> });
>
>
> $(document).ready(function(){
> //do the rest of the "window.onload" events here
> });
>
> I've been looking through the source, and it seems to me that doing
> $('#mydiv').ready(function(){}); will fire when the whole DOM has
> loaded, which will probably be a little late for me.
>
> Any idea on how I can do this?
>
> Phill
Use an interval and constantly poll that element until it is found...
var tries = 0;
(function(selector) {
var elem = $(selector)[0];
if (!elem && tries < 10) { // try max 10 times to find element...
setTimeout(function() {
arguments.callee(arguments);
}, 100);
tries++;
} else if (elem) {
// do something with elem
}
})('#your-elem');
Just an idea, untested and could possibly be optimized (not sure about
arguments.callee there).
Or simply include your script after the element.
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/