SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 83 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

getElementById(elId);
if (el)
{
callback();
}else{
CHAPTER 2 n HTML, CSS, AND JAVASCRIPT 42
this.polled[this.polled.length] = a
{'element':elId, 'callback':callback};
this.startPoll();
}
}
};
ElementReady.chkDomId('message',doStuff);
ElementReady.chkDomId('message2',doStuff2);
window.onload = function() {
ElementReady.cleanUp();
};
Element Ready has a number of methods and properties, most of which are for internal
use. The two key functions include chkDomId() and cleanUp(). The chkDomId() function takes
two parameters: the first is the ID of the object you want to retrieve, and the second is the
function you want to call once the element is available. The cleanUp() function is run on
window.onload to make sure to double-check that all the elements are loaded and to run the
callback function if it is.
Dean Edwards (http://dean.edwards.name) has done some testing and (with a few other
folks) has come up with a way to check that the document is completely loaded that works in
most browsers. Unfortunately, the solution is different for each browser, and some are only for
the more recent versions of a particular browser.
// for Mozilla and Opera 9+ browsers
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("