I'm new to Javascript and I am trying to simplify my life by integrating many functions into one.
I have a very simple operation which allows for the click of a button to load a specific image in place of a default image. As oppose to having many functions which do the same thing, I'd rather have just one.
I imagine you can store the images in an array and select them by position?
Here is what I have so far.
function swap1() {
document.getElementById("default").src="321.jpg";
}
function swap2() {
document.getElementById("default").src="432.jpg";
}
function swap3() {
document.getElementById("default").src="742.jpg";
}
<input type="button" onClick="swap1()">
<input type="button" onClick="swap2()">
<input type="button" onClick="swap3()">