Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Eight Weeks of Prototype: Week 4, Event Handling in Prototype

Checking for Stopped Events

As mentioned in the previous section, if you have multiple event handlers, each of them will still be executed even if you called Event.stop() at any time. You can, however, check to see if an earlier handler has already stopped the event by reading the stopped property.

Listing 8 shows an example of doing this. In it, I have defined two different handlers for the click event, each of which will display an alert box. However, the alert box will only be shown if the event hasn't already been stopped.

Listing 8 Checking for stopped events (listing-8.html)
        <title>Checking for stopped events</title>
        <script type="text/javascript" src="/js/prototype.js"></script>
        <div id="foo">
            Click here
        <script type="text/javascript">
            function handler1(e)
                if (!e.stopped) {
                    alert('Handler 1');
            function handler2(e)
                if (!e.stopped) {
                    alert('Handler 2');
            $('foo').observe('click', handler1);
            $('foo').observe('click', handler2);

In This Article