- jQuery Examples
- Examples - Home
- Examples - Set up
- Examples - Selectors
- Examples - Attributes
- Examples - Traversing
- Examples - CSS
- Examples - DOM
- Examples - Events
- jQuery Useful Resources
- jQuery - Quick Guide
- jQuery - Useful Resources
jQuery Examples - error( fn )
Description
The error(fn) method binds a function to the error event of each matched element.
Syntax
Here is the simple syntax to use this method −
selector.error(fn)
Parameters
Here is the description of all the parameters used by this method −
fn − A function to bind to the event on each of the set of matched elements.
Example
Following is a simple example showing the usage of this method. Here it binds a function to the error event of each matched element −
<html> <head> <title>The jQuery Example</title> <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("img").error(function() { alert("image not found. Showing default image."); $("img").attr( "src", "http://www.tutorialspoint.com/jquery/images/logo.png" ); }); }); </script> </head> <body> <form name = "sampleForm"> <img src="missing.png"> </form> </body> </html>
This will produce following result −
jqueryexamples_events.htm
Advertisements
To Continue Learning Please Login
Login with Google