Jquery has a handy way of allowing you to do stuff as soon as the document object model for a page has loaded (ie. as soon as the browser has loaded all your markup). I’m currently working on a project that requires Prototype JS, and I had some difficulty finding the equivalent method.. hence this post.

I knew Prototype had evolved somewhat since I’d last used it extensively back in late 2006, and I also suspected they had implemented something similar.. but Google was not forthcoming.

The traditional way to do this (pre jQuery) was to put your javascript directly before the closing body tag. This way the browser is unable to execute it prior to loading the rest of the page. However this is kind of clunky if you are trying to abstract your javascript to a linked file, or would like to keep your behavioral code (javascript) separate to your markup (xhtml).

An alternative is to use the onload event – in Prototype you would use something like