I have the following html file :
<div id="tour">
<h2>Paris, France Tour</h2>
<p>$2,499 for 7 Nights</p>
<button>See photos from our last tour</button>
<ul class="photos">
<li>
<img src="/assets/photos/paris1.jpg">
<span>Arc de Triomphe</span>
</li>
<li>
<img src="/assets/photos/paris2.jpg">
<span>The Eiffel Tower</span>
</li>
<li>
<img src="/assets/photos/paris3.jpg">
<span>Notre Dame de Paris</span>
</li>
</ul>
</div>
This is my jQuery code :
function showPhotos()
{
$(this).find("span").slideToggle();
}
$(document).ready(function() {
$("#tour").on("click", "button", function() {
$(".photos").slideToggle();
});
$(".photos").on("mouseenter", "li", showPhotos);
$('.photos').on("mouseleave", "li", showPhotos);
});
This code works, it shows the span when mouse enters the img element . But when I try to do the same thing like so :
function showPhotos()
{
$(this).find("span").slideToggle();
}
$(document).ready(function() {
$("#tour").on("click", "button", function() {
$(".photos").slideToggle();
});
$(".photos").on("mouseenter", "li", function() {
showPhotos();
});
$('.photos').on("mouseleave", "li", function() {
showPhotos();
});
});
It doesn't work . With my limited knowledge, both codes seem to be doing the same thing. Please help me, How is the second code different from the first ?