Tuesday, January 31, 2017

Fix Broken Image link Using Jquery

This is a quick solution to fix broken image problem using jquery, Suppose we have a web page that includes a bunch of images. Sometimes the image isn’t available, so a broken image is displayed in the client’s browser and replacing them one by one isn’t easy, so adding this simple piece of code can save you a lot of headaches. Even if you don’t have any broken links adding this doesn’t do any harm.

Here is the simple jquery code to replace / fix broken image problem.
<script>
$(function() {  
 $('img').error(function(){
  $(this).attr('src', ‘image/broken.png);
 });
});
</script>

No comments:

Post a Comment