Detect the exchange of an image

0

Personal I have an img tag that has a button that loads several images for the person to choose, so he chooses the src of this tag is changed. I need to detect when this src change occurs and display an alert. I tried with the onchange but it did not fire, with the load it worked out but it also fired at loading the page because as soon as the pagian loads there a standard image appears.

$(".imagem").on("change", function(e){alert("alterou")});
    
asked by anonymous 06.04.2015 / 21:30

1 answer

2

You need to register the event with load after the page has been fully loaded:

$(window).load(function() {
    $('.image').on('load', function() {
        alert('Imagem alterada');
    });
});

See working at JSFiddle

    
06.04.2015 / 22:11