So I'm curious if there is a better way to change a single img src
with multiple a href
images
I am using multiple onclick functions but I am mostly curious if I can create one single function to do this
x = document.getElementById("myImages-1").src = "<img src='https://i.stack.imgur.com/L7Iwr.png'>";
function imageChange() {
document.getElementById("mySlides").innerHTML = x;
}
y = document.getElementById("myImages-2").src = "<img src='https://i.stack.imgur.com/cA4jE.png'>";
function imageChange1() {
document.getElementById("mySlides").innerHTML = y;
}
<html><body><div id="content"><div id="mySlides"><img src="https://i.stack.imgur.com/COgXm.png" width="100px" height="100px"></div><a onclick="imageChange()" id="myImages-1" href="#"><img src="https://i.stack.imgur.com/L7Iwr.png" width="100px" height="100px">Hello World</a><a onclick="imageChange1()" id="myImages-2" href="#"><img src="https://i.stack.imgur.com/cA4jE.png" width="100px" height="100px">Hello World</a></div></body><script src="javascript.js"></script></html>