change src jquery code example

Example 1: jquery change image src

//change image src with jquery
$("#myImageID").attr("src","images/my_other_image.png");

//change image src plain javascript
document.getElementById('myImageID').src="images/my_other_image.png";

Example 2: jquery change picture source

$("#my_image").attr("src","second.jpg");

Example 3: jquery change picture onclick

<!-- https://codepen.io/poliweb/pen/eYJNqLM -->
<!-- https://stackoverflow.com/questions/26377231/jquery-how-to-change-img-src-path-onclick -->

<div class="img-container">
  <img id="changeMe" src="">
</div>

<img class="preview" src="images/preview-1.jpg">
<img class="preview" src="images/preview-2.jpg">
<img class="preview" src="images/preview-2.jpg">
  
 <!-- Script --> 
  
  $('.preview').on('click',  function() {
    $('#changeMe').prop('src', this.src);
});

Example 4: change image src jquery

$(document).ready(function () {
    $('img').click(function(){
        $(this).attr('src','images/download.jpeg')
      })
})

Example 5: jquery change picture src

<img id="my_image" src="first.jpg"/>
<script>
//Then you can change the src of your image with jQuery like this:
$("#my_image").attr("src","second.jpg");
</script>