jQuery focus() Method (original) (raw)

Last Updated : 12 Sep, 2024

**The jQuery focus() method is used to set the focus on a specified element, such as an input field or textarea. It triggers the browser's focus event, enabling user interaction with the element, like typing or clicking.

**Syntax:

$(selector).focus(function)

Here selector is the selected element.

**Parameter: It accepts an optional parameter in the form of a callback function which will be called once the focus event occurs.

**Example 1: In this example we use jQuery's focus() method to display a hidden element when an field is focused, changing the 's display style to inline.

HTML `

jQuery focus() Method