<p>Jquery has a great language construct that looks like this:</p>

<pre><code>$(document).ready(function() {
    $("a").click(function() {
        alert("Hello world!");
    });
});
</code></pre>

<p>As you might guess this, once the document has loaded, binds a custom function to the onClick event of all <strong><em>a</em></strong> tags.</p>

<p>The question is, how can I achieve this same kind of behavior in Prototype?</p>

[{'answer_id': 49618, 'author': 'David McLaughlin', 'author_id': 3404, 'author_profile': 'https://Stackoverflow.com/users/3404', 'pm_score': 1, 'selected': False, 'text': '<pre><code>Event.observe(window, \'load\', function() { \n     Event.observe(element, \'click\', function() { \n         alert("Hello World!");\n     });\n});\n</code></pre>\n\n<p>Of course you need to "select" the elements first in Prototype. </p>\n'}, {'answer_id': 49654, 'author': 'erlando', 'author_id': 4192, 'author_profile': 'https://Stackoverflow.com/users/4192', 'pm_score': 4, 'selected': True, 'text': '<p>Prototype 1.6 provides the <a href="http://prototypejs.org/api/document/observe" rel="nofollow noreferrer">"dom:loaded"</a> event on document:</p>\n\n<pre><code>document.observe("dom:loaded", function() {\n    $$(\'a\').each(function(elem) {\n        elem.observe("click", function() { alert("Hello World"); });\n    });\n});\n</code></pre>\n\n<p>I also use the <a href="http://prototypejs.org/api/enumerable/each" rel="nofollow noreferrer">each</a> iterator on the array returned by <a href="http://prototypejs.org/api/utility/dollar-dollar" rel="nofollow noreferrer">$$</a>().</p>\n'}, {'answer_id': 173410, 'author': 'eyelidlessness', 'author_id': 17964, 'author_profile': 'https://Stackoverflow.com/users/17964', 'pm_score': 2, 'selected': False, 'text': "<pre><code>$(document).observe('dom:loaded', function() {\n    $$('a').invoke('observe', 'click', function() {\n        alert('Hello world!');\n    });\n});\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/49599', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/305/']