Icon Patrick Gibsonpatrickgibson.com
news and such projects, etc. movies writings hyperlinks contact
search:
news and stuff

Saturday, October 11, 2008

The domready event for Prototype

I've been a Mootools user for a while, but Prototype was a better fit for a project I was working on. Mootools adds the domready event to the window object which fires when the DOM has finished loading. This is a lot nicer than window's built-in onload event which fires after everything has loaded including images, stylesheets, etc.

When I started with Prototype, I could not find the equivalent, and Google searches came up with other people's add-ons for Prototype to bring this functionality in. I tried a few that I found, and I couldn't get any to work reliably. I modified the best code I found, merging some ideas from Yahoo's YUI library and eventually got it working. The other day, however, I found that Prototype actually does have this already built-in; it's just that it's part of the document object, and has a different name: dom:loaded. To use it, you do:

document.observe("dom:ready", function() { alert("The DOM has loaded!"); });

Here's the link to Prototype's documentation on this.

Posted at 11:25
« UPS: "Sir, there are no guarantees in life." | Back to News and Such | Changing window.location in IE 6 »

Comments

this is exactly the solution I was looking for...prototype's built-in are much better that any add-ons
Thank you very much...

- Yasel, Wednesday, May 20, 2009


Post a comment

Name:

Email Address: (optional)

Website: (optional)

Comments:

Enter the number shown here:

back

Retrix Hosting