dimanche 3 janvier 2016

Image source not incorrectly recognized by function

I have two images: img id="img1" src="l1.jpg" usemap="#lb" height="400" border="0" width="300"> and <img src="images.jpg" id="img2".

Then I have a javascript:

 <script>
      function checkImg (){
      if (document.getElementById('img2').src=="images.jpg") 
    { if (document.getElementById('img1').src=="l1.jpg")
            { window.alert("hi");}
      }

     else { window.alert("bye");}
      }
    checkImg();
 </script>  

And a button that activates it:

<button type="button" onclick="checkImg()">Click Me!</button>

Both images have the source as specified in the script, though it still alerts 'bye' instead of 'hi'. What's wrong?

Aucun commentaire:

Enregistrer un commentaire