Changing an image src

<img id="my_image" src="images/image1.png" width="22" height="8">

<script>
//Chage the image source:
document.getElementById("my_image").src="images/image2.png";
</script>

Using jQuery to change an image src

//We're using some variables just to demonstrate how they can get used sucessfully
  let my_image_id_value = "34";
  let my_image_filename = "sgflkjdsdfrglhg.jpg"

  jQuery("#my_image_id_" + my_image_id_value).attr("src", "/live_camera_images/" + my_image_filename);     //<<<<<Don't forget the "#" at the start of the ID name!!!
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *