You can add dynamic event handlers to elements on your site. To add an event handler to an element, you can either:
Write the event handler in your page code, either outside or inside the page’s onReady()
function. Access your page code files based on your setup:
src
folder.src
folder.Sample event handler:
You can add or modify event handlers dynamically in your code as needed, for example, $w('#myElement').myHandlerFunction()
.
To generate an event handler in the editor using the Properties & Events panel:
Inside the body of the event handler, add the code you want to execute when the event occurs.
For example:
Note:
When you add an event handler using the Properties & Events panel, the event handler code is placed outside the onReady()
function. You can then move the generated code snippet to any location.
For a complete list of supported event handlers for each element type, see the Wix API Reference.