jeudi 21 mai 2015

Javascript - if statement not changing image src

I'm just wondering if anyone can point out to me where I'm going wrong.. Here I have a small snippet of code that I would like to use to toggle between two images based on an onclick event. However, upon clicking on the image nothing happens. I placed an alert within the click function, which successfully triggered; though, when an alert was placed within the if statement, no alert was triggered. What did I mess up?

HTML:

<img id="pricetile2" src="../Images/french.png" data-price="100" />

JAVA:

$('#pricetile2').click(function(){

    if (document.getElementById("pricetile2").src == "../Images/french.png") 
    {

        document.getElementById("pricetile2").src = "../Images/french2.png";
    }
    else 
    {
        document.getElementById("pricetile2").src = "../Images/french.png";
    }   
});

Aucun commentaire:

Enregistrer un commentaire