enode.race()
enode.race() is used to add an event listener to the associated HTML element of the current enode.
This method is similar to enode.on(), but assigning more event types to a race. When an event type gets triggered, it is considered as winner and become the actual event of the event target. The other event types will be removed.
This is useful when dealing with difference in events across different platforms, e.g. PCs use event 'click', while mobiles use event 'touchend'.
Since this method is built on top of EventTarget.addEventListener() in Web APIs, their usage is kind of the same.
Syntax
JavaScript
enode.race(eventType: String, eventCallback: Function, options: Object)
Parameters
eventType
- A case-sensitive string specifying the list of event types which are separated by white spaces.
eventCallback
- The event handler function to add to the event target.
options (optional)
- An object that specifies characteristics about the event listener. For available options, read here.
Return value
The current enode, ready for the chaining method calls.
Examples
JavaScript
var button = new Binh.ElementNode(document.createElement('button'));
button.race('click touchend', function(event) {
// hanle event
alert('selected');
});