W3Schools.com

jQuery Event focus() Method

jQuery Event Methods jQuery Event Methods

Example

Change background color of an input field when it gets focus:

$("input").focus(function(){
  $("input").css("background-color","#FFFFCC");
});

Try it yourself »

Definition and Usage

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 focus Event

Trigger the focus event for the selected elements.

Syntax

$(selector).focus()

Try it yourself »


Bind a Function to the focus Event

Specifies a function to run when the focus event occurs for the selected elements.

Syntax

$(selector).focus(function)

Try it yourself »

Parameter Description
function Optional. Specifies the function to run when the focus event occurs


jQuery Event Methods jQuery Event Methods


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE