Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
jQuery plugin to detect and replace broken or slow-loading images
JavaScript
branch: master
Failed to load latest commit information.
README.markdown Remove reference to Github pages URL and update copyright date
bower.json Add bower.js
brokenimage.jquery.json
jquery.brokenimage.js Add jQuery plugins manifest and version bump to 1.0.0
test.html Migrate code.jquery.com to Google AJAX Libraries API (see http://blog…

README.markdown

brokenImage: a jQuery plugin

brokenImage is a jQuery plugin that is able to detect and replace images that are either broken or are taking a long time to load. If no replacement image is specified then the CSS visibility is set to hidden.

Usage

Fix a broken Image object:

  var image = new Image();
  image.src = '/might/be/broken.png';
  image.brokenImage();

Fix a broken image tag:

  <img src="/might/be/broken.png" alt="Might be broken" id="myImage" />

  $('#myImage').brokenImage();

Fix a collection of images:

  <div id="myImages">
    <img src="/might/be/broken" alt="Might be broken" />
    <img src="/might/also/be/broken" alt="Might also be broken" />
  </div>

  $('#myImages img').brokenImage();

Set a custom image replacement instead of setting the visibility to hidden:

  image.brokenImage({replacement: '/images/placeholder.png'});

Set a custom timeout to override the 5 second default:

  image.brokenImage({timeout: 100}); // 100 ms

Licensing

Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php

Copyright (c) 2011 Stateless Systems (http://statelesssystems.com)

Something went wrong with that request. Please try again.