## .error( handler )Returns: jQuery version deprecated: 1.8, removed: 3.0

Description: Bind an event handler to the "error" JavaScript event.

- #### version added: 1.0.error( handler )

  - handler
    Type: Function( Event eventObject )
    A function to execute when the event is triggered.

- #### version added: 1.4.3.error( [eventData ], handler )

  - eventData
    Type: Anything
    An object containing data that will be passed to the event handler.
  - handler
    Type: Function( Event eventObject )
    A function to execute each time the event is triggered.

This method is a shortcut for `.on( "error", handler )`.

As of jQuery 1.8, the `.error()` method is deprecated. Use `.on( "error", handler )` to attach event handlers to the `error` event instead.

The `error` event is sent to elements, such as images, that are referenced by a document and loaded by the browser. It is called if the element was not loaded correctly.

For example, consider a page with a simple image element:

1 |
    <img alt="Book" id="book">

The event handler can be bound to the image:

1 2 3 4 5 |
    $( "#book" )  .error(function() {    alert( "Handler for .error() called." )  })  .attr( "src", "missing.png" );

If the image cannot be loaded (for example, because it is not present at the supplied URL), the alert is displayed:

`Handler for .error() called.`

The event handler must be attached before the browser fires the `error` event, which is why the example sets the `src` attribute after attaching the handler. Also, the `error` event may not be correctly fired when the page is served locally; `error` relies on HTTP status codes and will generally not be triggered if the URL uses the `file:` protocol.

Note: A jQuery `error` event handler should not be attached to the `window` object. The browser fires the `window`'s `error` event when a script error occurs. However, the window `error` event receives different arguments and has different return value requirements than conventional event handlers. Use `window.onerror` instead.

### Additional Notes:

- As the `.error()` method is just a shorthand for `.on( "error", handler )`, detaching is possible using `.off( "error" )`.

## Example:

To replace all the missing images with another, you can update the `src` attribute inside the callback passed to `.error()`. Be sure that the replacement image exists; otherwise the `error` event will be triggered indefinitely.

1 2 3 4 5 6 |
    // If missing.png is missing, it is replaced by replacement.png$( "img" )  .error(function() {    $( this ).attr( "src", "replacement.png" );  })  .attr( "src", "missing.png" );