English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The focus() method triggers the focus event, or you can attach a function to run when the focus event occurs.
Focus events occur when an element gains focus (by clicking the mouse or selecting it via 'tab navigation').
This method is usually used withblur()Methods used together.
Trigger the focus event of the selected element:
$(selector).focus()
Attach a function to the focus event:
$(selector).focus(function)
Trigger the focus event of <input>:
$(document).ready(function(){ $("input").focus(); });Test and see‹/›
Attach a function to the focus event (the focus event occurs when the <input> field gains focus):
$("input").focus(function(){ $(this).next("span").css("display", "inline").fadeOut(2000); });Test and see‹/›
Attach a function to the focus event (the focus event occurs when the <input> field gains focus):
$("input").focus(function(){ $(this).css("background", "white"); });Test and see‹/›
Parameter | Description |
---|---|
function | Function executed each time a focus event is triggered |