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 define Global Variable in JavaScript?
jQuery Show or Hide text on button click
How to current URL, HOST and URL attributes using JavaScript or jQuery?
How to check a variable is undefined in JavaScript?
Get largest number from each sub-arrays
Check if a string ends with the given target string
How to declare multiple variables in one statement in Javascript?
Write a function that splits an array into groups the length of size and returns them as a two-dimensional array
JavaScript convert string variable in boolean using Regex
How to join string with number in JavaScript?