Thanks Klaus, I'll have a play with that code and see if I can create a
plugin/extension to jQuery for such an event.
Klaus Hartl wrote:
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
begin:vcard
fn:Phillip Oldham
n:Oldham;Phillip
org:The Activity People;Systems Development
email;internet:[EMAIL PROTECTED]
title:Chief Programmer
tel;work:0870 162 4847
x-mozilla-html:TRUE
url:http://theactivitypeople.co.uk/
version:2.1
end:vcard
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/