Yo.utils.addEvent

Use this cross-browser function to create and register an event on the supplied DOM element using the method most appropriate for the shopper's browser.

Prerequisites

The following command to load the appropriate version of the Rapid+JS Library must precede the use of this function on the page. Specify your own site key:

<script src="https://rapid-cdn.yottaa.com/rapid/lib/sitekey.js"></script>

Syntax

Yo.utils.addEvent (element, eventName, eventHandler);

Returns

Not applicable

Parameters

Parameter

Description

element

The DOM element on which to create the event.

Example:

Yo.utils.select('#myButton')

eventName

The name of the event to create. String. Omit the word "on".

eventHandler

The function that will be called when the event is triggered. Either the name of the function or the full code for a function.

Example

This example creates a button, then adds an event to the button that writes a statement to the log when the user clicks the button.

<button id='myButton'>My Button</button>
Yo.utils.addEvent(Yo.utils.select('#myButton'), 'click', function() {
        Yo.utils.log('button was clicked');
});