Javascript DOM HTML Image src Property set from image array

Description

Javascript DOM HTML Image src Property set from image array

View in separate window

<!DOCTYPE html> 
<html lang="en"> 

<body> 
   <img src="" width="200" height="150" alt="My Image" /> 
   <script> 
       let myImages = [ //from w  w  w.ja v  a  2  s . c  om
           "image1.png", 
           "image3.png", 
           "image4.png", 
           "image2.png" 
       ]; 
       let imgIndex = 2; 
       document.images[0].src = myImages[imgIndex]; 
   </script> 
</body> 
</html> 



PreviousNext

Related