Your understanding of sequence is correct: event happens, event is handled by function, function changes source of the image
But when you change the image .src
you do not change the ID - DOM element <img>
remains the same, only its source changed, so you can still access it by the original ID:
function mOut() {
document.getElementById("img1").src="image1.jpg";
}