javascript image src 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: javascript change image src

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

Example 3: javascript check image src

if (img.getAttribute('src') === 'on.png')

Example 4: how to change image source using javascript

document.getElementById("myImg").src = "hackanm.gif";

Example 5: set img src using javascript

document.getElementById("imageid").src="../template/save.png";

Example 6: js get image src

var youtubeimgsrc = document.getElementById("youtubeimg").src;