Replacing images using onerror for <img> element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Replacing images using onerror for <img> element

Demo Code

ResultView the demo in separate window


<html>
   <head> 
      <script>
function imgError(image) {/*from w ww  .j ava  2 s .  c om*/
    image.onerror = "";
    image.src = "http://www.java2s.com/style/download.png";
    return true;
}

      </script> 
   </head> 
   <body> 
      <img src="image.gif" onerror="imgError(this);">  
   </body>
</html>

Related Tutorials