Use function to return image src path - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Use function to return image src path

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
function getImagePath() {//from   ww  w.j av a  2  s . c  o m
  return "http://www.java2s.com/style/download.png";
}

      </script> 
      <!-- doesn't fire error event in FireFox --> 
      <img src onerror="this.onerror=null; this.src=getImagePath();">  
   </body>
</html>

Related Tutorials