Hi friends:
I was successful with toggling two photos. I am trying to expand it to four photos without any success. I am grateful for your helps.
I was successful with toggling two photos. I am trying to expand it to four photos without any success. I am grateful for your helps.
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Switch Images</title>
<style>
*{margin: 0; padding: 0; box-sizing: border-box; }
p{font-size: 24px;}
</style>
</head>
<body>
<p>between two images</p>
<div>
<img src="one.jpg" id="images1">
</div>
<p>between four images</p>
<div>
<img src="three.jpg" id="images2">
</div>
<script>
const img = document.getElementById('images1');
let toggle = true;
img.addEventListener('click',function(){
toggle = !toggle;
if(toggle){
img.src = 'one.jpg';
}else{
img.src = 'two.jpg';
}
});
</script>
<script>
const img2 = document.getElementById('images2');
let toggle2a = true;
let toggle2b = true;
img2.addEventListener('click',function(){
toggle2a = !toggle2a;
toggle2b = !toggle2b;
if(toggle2a){
img2.src = 'one.jpg';
}else
{if(toggle2b){
img2.src= 'two.jpg'
}else{
img2.src='three.jpg'
}
img2.src = 'four.jpg';
}
});
</script>
</body>
</html>