Search code examples
jqueryimagesrcattr

Exchanging an image with jQuery?


Can anybody tell me why the following code (also see jsfiddle) does not replace 1tw.gif with 2tw.gif? It should show "2" instead of "1"...

<img id="pic" src="http://www.drewgreenwell.com/images/sample/1tw.gif" alt="" width="90%"/>

<script>
$(document).ready(function(){
$('#pic').attr('scr', 'http://www.drewgreenwell.com/images/sample/2tw.gif');
});
</script>

Thank you!


Solution

  • You have typo. scr should be src:

    $('#pic').attr('src', 'http://www.drewgreenwell.com/images/sample/2tw.gif');
    

    Demo