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
How to set checkbox and radio option checked on load with jQuery?
Get largest number from each sub-arrays
How to change text color on click using JavaScript?
How to declare and print value of variable in JavaScript?
jQuery simple form validations between start date and end date
Check if a string ends with the given target string