Skip to content Skip to sidebar Skip to footer

How To Trigger Events (onclick) With Specific Orders In Js/prototype

Possible Duplicate: Trigger an event with Prototype example, 3 onclick events in javascript/prototype. How to force prototype to run alert functions for dump 'first!', 'second!'

Solution 1:

Event handlers are functions in JavaScript, and functions are prime citizens in JavaScript. Usually a middle object contains the list of all handlers as an array. For example, in jQuery, data('events') holds the event handlers. Unless prototype has an straightforward, you should manually fetch all handlers, order them up and assign them back.

Or

As @gaby has said, you can bind them using correct order in you markup at first place.

Solution 2:

How about this:

var handlers = [func1, func2, func3];
$("go").observe("click", function() { 
    var i = 0, len = handlers.length;
    for(i; i<len;i++)
       handlers[i]();
});

There are improvements of course, but it's a general idea

Post a Comment for "How To Trigger Events (onclick) With Specific Orders In Js/prototype"