When a user clicks on either button I’d like for the name of the location to fadeIn but I’m not able to get it to work with this conditional statement. I have a "Next" and a "Previous" button.
I was thinking by referencing the current element using e.target I could fadeIn() the extra information in my elements relevant to to each specific picture when the user clicks over to that picture
HTML
<div class="divs">
<div id="motion1"><img class="motion" src="./c1.jpg"><span class="info">Copacabana</span></div>
<div><img id="motion2" class ="motion" src="./c2.jpg"><span class="info">Ipanema</span></div>
<div><img id="motion3" class="motion" src="./c3.jpg"><span class="info">Florianópolis</span></div>
<div><img id ="motion4" class="motion" src="./c4.jpg"><span class="info">Jericoacoara</span></div>
<div><img id="motion5" class="motion" src="./c5.jpg"><span class="info">Praia da Trindade</span></div>
<div><img id="motion6" class="motion" src="./c6.jpg"><span class="info">Porto de Galinhas</span></div>
</div>
$(function() {
$(".divs div:not('#motion1')").hide();
let $span = $("span");
$span.hide();
THIS IT THE CONDITIONAL STATEMENT ATTACHED THE CLICK EVENT IN QUESTION
$("#button2").on("click", function(e) {
let target = e.target;
if ($(this) == target) {
$span.fadeIn();
}
})
2
Answers
As I understand from your explanation. You want to show the related info inside the span which belongs to the picture that is clicked.
Here is an example code produced from your code to showcase this. Check it out if this is what you want.
I think this is what you want if I understand your question correctly.
I will move
.motion
to bothimg
‘s &span.info
‘s parent element so it is easily to chooseimg
and their.info
bythis
.show
function will only show 1 picture depend oni
.$('.motion').on('click' ...
will show & hide.info
when user clickimg
.$('button').on('click' ...
will switchimg
and.info
.