Mootools Domready

Don't use window.onload to run code as soon as the page is loaded, instead, use the mootools way, called the DomReady event. (More on Events later.) Code wrapped inside of DomReady will execute as soon as the DOM is ready to be interacted with.

Do this,

 window.addEvent("domready", function(){
  // Your code goes here.
 });

instead of,

window.onload = function(){
 // Your code here.
};

The advantages of this is that you do not need to wait for slow external resources (like images) to load.

Additionally, there is also an alternative syntax for this.

 function myFunction() {
  // Your code here.
 }
 
 window.addEvent("domready", myFunction);

This attaches the myFunction to the DomReady event to run when it (the event) is fired.

Keep in mind: the code presented in the rest of the walkthrough, if not explicitly being called by another function/method will probably be called with the domready event.

Next: The $ Function

 
1.2.x/basic/domready.txt · Last modified: 2009/02/21 04:28 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki