Example
<!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>
Most Helpful This Week
jQuery simple form with name and email validations
How to define Global Variable in JavaScript?
How to change the height of Textarea on click?
Example to take user input and display on screen using JavaScript
How to declare multiple variables in one statement in Javascript?
Highlight and get the details of table row on click using JavaScript