Search.../

onClick( )

Adds an event handler that runs when the element is clicked.

Description

An element receives a click event when a user clicks on the element and releases.

You can also define an event handler using the Properties and Events panel.

Properties and Events panel

This will automatically add the required code for the selected element and event:

export function button1_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
}
javascript | Copy Code

Syntax

function onClick(handler: EventHandler): Element
handler: function EventHandler(event: Event): void

onClick Parameters

NAME
TYPE
DESCRIPTION
handler

The name of the function or the function expression to run when the element is clicked.

Returns

The element to which the event handler was added.

Return Type:

EventHandler Parameters

NAME
TYPE
DESCRIPTION
event

The event that occurred.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Open a dashboard panel when the user clicks a button

Copy Code
1import wixEditor from 'wix-editor'
2
3$w.onReady(function () {
4 $w('#myButton').buttonLabel = "Manage Contacts"; // Set the button's label
5 $w('#myButton').onClick(async () => {
6 await wixEditor.openDashboardPanel({ url: "/contacts" }) // Open the site Dashboard's Contacts page
7 })
8});