Frontend event handlers in Wix work differently than in vanilla JavaScript. Normally, you would use addEventListener() to add event handlers, selecting DOM elements with methods like getElementById() or querySelector().
For example, you might write:
In Wix, however, you don't access the DOM directly. Instead, you use the $w API to interact with elements in the Wix Editor and add event handlers, like this:
Although you need to create event handlers using the Velo API, you can use SDK code in the event handler body.
For example:
You can use event handlers in the following IDEs:
Wix's static event handlers have been deprecated. While static event handlers are still supported for existing sites, we recommend using dynamic event handlers for new development and when updating existing code.