onClick( )


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

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

When a user double-clicks an element, two click events are fired before a doubleClick event is also fired.

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:

Copy
1

Note: To avoid unpredictable behavior, don't set redirect links in the editor for elements that already have an onClick event handler.

Method Declaration
Copy
Method Parameters
handlerfunctionRequired

handler(event: MouseEvent): void The name of the function or the function expression to run when the element is clicked.

Returns
Return Type:Element
Was this helpful?
Yes
No