This feature is deprecated but will continue to work as expected. Switch to dynamic event handlers for your current and future projects. Unlike static event handlers, dynamic event handlers can be added or removed using methods like $w('#myButton').onClick()
. While static event handlers are still supported for existing sites, we recommend using dynamic event handlers going forward.
A static event handler is predefined and is linked to a specific event. The function can’t be dynamically modified or removed programmatically during execution.
Sample static event handler:
export function myButton_click(event) {
console.log("Button clicked");
}
To migrate a static event handler to a dynamic one:
After migration, your code updates from the old static format to the new dynamic format. For example:
Old format:
export function myButton_click(event) {
// Existing code
}
New format:
$w("#myButton").onClick((event) => {
// Existing code
});
You can no longer use the Properties & Events panel to delete static event handlers. To delete a static event handler, delete the generated code from the page code file.