jQuery focus() method
Example
Add a function to the focus event. When the field gains focus, a focus event occurs:
$
(
"
input
"
)
.
focus
(
function
(
)
{
$
(
"
span
"
)
.
css
(
"
display
"
,
"
inline
"
)
.
fadeOut
(
2000
)
;
}
)
;
Try it »
Definition and Usage
The focus event occurs when an element gains focus (when the element is selected by a mouse click or located via the tab key).
The focus() method triggers the focus event, or specifies a function to run when a focus event occurs.
**Tip:** This method is usually used together with blur() the method.
Syntax
Trigger the focus event of the selected element:
$(
selector
).focus()
Try it
Add a function to the focus event:
$(
selector
).focus(
function
)
Try it
| Parameters | Description |
|---|---|
| function | Optional. Specifies the function to run when the focus event occurs. |
jQuery event methods