Search.../

onFocus( )

Adds an event handler that runs when the element receives focus.

Description

An element receives focus through user actions, such as clicking and tabbing, or programmatically, using the focus( ) function.

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

Note: onFocus() has no effect when applied to RadioButtonGroup elements.

Syntax

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

onFocus Parameters

NAME
TYPE
DESCRIPTION
handler

The name of the function or the function expression to run when the element receives focus.

Returns

The element on which the event is now registered.

Return Type:

EventHandler Parameters

NAME
TYPE
DESCRIPTION
event

The event that occurred.

Returns

This function does not return anything.

Return Type:

void
Mixed in from:$w.FocusMixin

Related Content:

Was this helpful?

Get the ID of the element that has received focus

Copy Code
1$w("#myElement").onFocus( (event) => {
2 let targetId = event.target.id; // "myElement"
3});