$(document).ready(function() { $('.but').on('click',function(){ $('img#aaa').attr('src', $(this).attr('id')+'.png'); }); });
<img id="aaa" src="oldimg.png"> <button class="but" id="newimg">push</button>