Description
The focus event occurs when an element gets focus (when selected by a mouse click or by "tab-navigating" to it)
The .focus() method triggers the focus event, or specifies a function to run when a focus event occurs.
Trigger the Event
Trigger the focus event for the selected elements.
This method has the form:
.focus()
Return Value
This form returns a jQuery object.
Bind a Function to the Event
Specifies a function to run when the focus event occurs for the selected element.
This method has the alternate form:
.focus(function)
Parameter | Description |
---|---|
function | (optional) Specifies the function to run when the focus event occurs |
Return Value
This form returns a jQuery object.
This method has the alternate form:
.focus(data,function)
Parameter | Description |
---|---|
data | (optional) Specifies additional data to pass along to the function |
function | (optional) Specifies the function to run when the focus event occurs |
Return Value
This form returns a jQuery object.
Examples
Change background color of an input field when it gets focus:
$("input").focus(function(){
$("input").css("background-color","#FFFFCC");
});