$(".link1").click(function(){
$(".slide2, .slide3, .slide4, .slide5").css("opacity", 0.0);
$(".slide1").fadeTo("slow", 1.0);
});
$(".link2").click(function(){
$(".slide1, .slide3, .slide4, .slide5").css("opacity", 0.0);
$(".slide2").fadeTo("slow", 1.0);
});
$(".link3").click(function(){
$(".slide2, .slide1, .slide4, .slide5").css("opacity", 0.0);
$(".slide3").fadeTo("slow", 1.0);
});
$(".link4").click(function(){
$(".slide2, .slide3, .slide1, .slide5").css("opacity", 0.0);
$(".slide4").fadeTo("slow", 1.0);
});
$(".link5").click(function(){
$(".slide2, .slide3, .slide4, .slide1").css("opacity", 0.0);
$(".slide5").fadeTo("slow", 1.0);
});
.slide1, .slide2, .slide3, .slide4, .slide5 {
position: absolute;
left: 0%;
top: 0%;
right: 0%;
bottom: 0%;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
margin: 0 auto;
width: 50vw;
height: 50vh;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
background-color: #fff;
opacity: 0;
}
.link1, .link2, .link3, .link4, .link5 {
width: 100px;
height: 100px;
margin-right: 133px;
margin-left: 2px;
padding-left: 0px;
}
.thumbWrapper{
position: absolute;
left: 0%;
top: 0%;
right: 0%;
bottom: 0%;
padding-bottom: 0px;
background-color: #fff;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<div>
<div class="thumbWrapper">
<div><a href="#" class="link1"><img src="https://images.unsplash.com/photo-1578491133524-f33d9c7a7484?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w...
</div>
</p>
<p>I will have 40 different thumbs and 40 large images that are placed all on absolute with their opacity set to zero.
On thumb click, the image should fade in. I started some code for just 5 links but I feel like there must be a shorter way to do this for my 40 links... Any ideas?</p>
<p>Thank you!!!</p>
<p>I have written this so far:</p>
<p><div>
<div>
<pre class="lang-js"><code><script>
$(".link2").click(function(){
$(".slide11, .slide1, .slide3, .slide44, .slide55, .slide66").css("opacity", 0.0);
$(".slide2").fadeTo("slow", 1.0);
});
$(".link1").click(function(){
$(".slide2, .slide1, .slide3, .slide44, .slide55, .slide66").css("opacity", 0.0);
$(".slide11").fadeTo("slow", 1.0);
});
$(".link3").click(function(){
$(".slide11, .slide1, .slide2, .slide44, .slide55, .slide66").css("opacity", 0.0);
$(".slide3").fadeTo("slow", 1.0);
});
$(".link4").click(function(){
$(".slide11, .slide1, .slide3, .slide2, .slide55, .slide66").css("opacity", 0.0);
$(".slide44").fadeTo("slow", 1.0);
});
$(".link5").click(function(){
$(".slide11, .slide1, .slide3, .slide44, .slide2, .slide66").css("opacity", 0.0);
$(".slide55").fadeTo("slow", 1.0);
});
</script>