How to use jQuery focus method with a demo

What is jQuery focus method?

Focus event happens when an element of HTML document gets focused by using mouse click or by using Tab key. At links (a href=””> the focus event occurs as its gets focus by using Tab key.

Whereas, the form fields like text boxes, text area etc gets focus event as the mouse is clicked into that element.

Syntax of using the focus jQuery method

This is how the focus method can be used:



  • $(“#txtbox”).focus(function)
  • $(“#link”).focus(function)

Running example of focus method

In the example below, the focus event is captured in two elements; one is a textbox and the other is a link. To check link focus, use Tab key and for text box use either Tab or mouse click.

The text ahead of the element will be shown as the focus event occurs by using the focus method of jQuery.

jQuery focus

Experience this example online

Also see set focus with focus method() | jQuery blur