Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

Looking for a better way to change an image with multiple images onclick

$
0
0

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>

Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>