Answers for "change images click div"

0

change images click div

<!DOCTYPE html>
<html>
<head>
    <title>onClick Demo</title>
</head>
<body>
<script>
function toggleImage() {
   var img1 = "http://placehold.it/350x150";
   var img2 = "http://placehold.it/200x200";
   
   var imgElement = document.getElementById('toggleImage');

   imgElement.src = (imgElement.src === img1)? img2 : img1;
}
</script>
<img src="http://placehold.it/350x150" id="toggleImage" onclick="toggleImage();"/>

</body>
</html>
Posted by: Guest on May-12-2021

Browse Popular Code Answers by Language