OnReady In A Smaller Package

I am sure most Javascript hackers are accustomed to the onready event. It is a pseudo-event that indicates the DOM of the pages has been loaded. document.onload is not as good as it won't fire until all the linked resources such as images are loaded as well, and if you have Javascript you want to run that can modify the appearance of the page, you would get an unwanted flicker at the beginning of the page. jQuery provides hooks to onready via $.ready(), and for prototype.js users, lowpro.js provides this via Element.onReady(). But, for hackers who don't want to use a large framework, I've created onready: the barebone implementation of the onready event. This might be useful if you want to write your own framework, or just need to write something that is very small or that has very few dependencies.

  1. Include file:

    <script type="text/javascript" src="onready.js"></script>
  2. Use:

    OnReady(function(){ alert('DOM is now ready!'); })
Ever feel like you are wasting your life away debugging?
It doesn't have to be this way. Check out my debugging course.
blog comments powered by Disqus