Skip to content Skip to sidebar Skip to footer

Html Button Change Image Source

Okay, I was wondering if this is possible. I want an image, and a totally separate button. When the button is clicked, I would like the Img Src to change from 'images/test' to 'im

Solution 1:

Firstly, your img tag is not closed in your code. Secondly, you can change the image src on click of the button using simple javascript or jQuery.

<html> 
<head> 
<script> 

function changeImage()
{
var img = document.getElementById("image");
img.src="images/test2";
return false;
}

</script>

</head>
<body>
<img id="image" src="images/test" />
<br><br><br>
<button id="clickme" onclick="changeImage();">Click to change image!</button>
</body>
</html>

Post a Comment for "Html Button Change Image Source"