# jQuery website jQuery documentation

## Events / UI

### focus(Function fn) : jQuery

fn | Function | A function to bind to the focus event on each of the matched elements.

Bind a function to the focus event of each matched element.

#### Example

##### Before

    <p>Hello</p>

##### Code

    $("p").focus( function() { alert("Hello"); } );

##### Result

    <p onfocus="alert('Hello');">Hello</p>

### focus() : jQuery

Trigger the focus event of each matched element. This causes all of the functions that have been bound to thet focus event to be executed.

#### Example

##### Before

    <p onfocus="alert('Hello');">Hello</p>

##### Code

    $("p").focus();

##### Result

    alert('Hello');

### onefocus(Function fn) : jQuery

fn | Function | A function to bind to the focus event on each of the matched elements.

Bind a function to the focus event of each matched element, which will only be executed once. Unlike a call to the normal .focus() method, calling .onefocus() causes the bound function to be only executed the first time it is triggered, and never again (unless it is re-bound).

#### Example

##### Before

    <p onfocus="alert('Hello');">Hello</p>

##### Code

    $("p").onefocus( function() { alert("Hello"); } );

##### Result

    alert('Hello'); // Only executed for the first focus

### unfocus(Function fn) : jQuery

fn | Function | A function to unbind from the focus event on each of the matched elements.

Removes a bound focus event from each of the matched elements. You must pass the identical function that was used in the original bind method.

#### Example

##### Before

    <p onfocus="myFunction">Hello</p>

##### Code

    $("p").unfocus( myFunction );

##### Result

    <p>Hello</p>

### unfocus() : jQuery

Removes all bound focus events from each of the matched elements.

#### Example

##### Before

    <p onfocus="alert('Hello');">Hello</p>

##### Code

    $("p").unfocus();

##### Result

    <p>Hello</p>

### blur(Function fn) : jQuery

fn | Function | A function to bind to the blur event on each of the matched elements.

Bind a function to the blur event of each matched element.

#### Example

##### Before

    <p>Hello</p>

##### Code

    $("p").blur( function() { alert("Hello"); } );

##### Result

    <p onblur="alert('Hello');">Hello</p>

### blur() : jQuery

Trigger the blur event of each matched element. This causes all of the functions that have been bound to thet blur event to be executed.

#### Example

##### Before

    <p onblur="alert('Hello');">Hello</p>

##### Code

    $("p").blur();

##### Result

    alert('Hello');

### oneblur(Function fn) : jQuery

fn | Function | A function to bind to the blur event on each of the matched elements.

Bind a function to the blur event of each matched element, which will only be executed once. Unlike a call to the normal .blur() method, calling .oneblur() causes the bound function to be only executed the first time it is triggered, and never again (unless it is re-bound).

#### Example

##### Before

    <p onblur="alert('Hello');">Hello</p>

##### Code

    $("p").oneblur( function() { alert("Hello"); } );

##### Result

    alert('Hello'); // Only executed for the first blur

### unblur(Function fn) : jQuery

fn | Function | A function to unbind from the blur event on each of the matched elements.

Removes a bound blur event from each of the matched elements. You must pass the identical function that was used in the original bind method.

#### Example

##### Before

    <p onblur="myFunction">Hello</p>

##### Code

    $("p").unblur( myFunction );

##### Result

    <p>Hello</p>

### unblur() : jQuery

Removes all bound blur events from each of the matched elements.

#### Example

##### Before

    <p onblur="alert('Hello');">Hello</p>

##### Code

    $("p").unblur();

##### Result

    <p>Hello</p>