Reputation: 151
I'm learning how jquery works and so far it's going good, but I'm stuck at the $(this)
object. And here is the part of the code that I don't understand well.
$(".photos").on("mouseenter", "li", function(){
$(this).closest(".photos").find("span").slideToggle();
});
The $(this)
is referring to the elements with the class photos( $(".photos") ) or to the li(s) which are inside at the elements with the class photos?
Upvotes: 0
Views: 76
Reputation: 93551
Inside the event handler, this
is the li
that that mouse has moved into so $(this)
is just that single element.
Because it is a delegated event handler, the "li" filter is applied to all mouseenter
events that bubble up to the .photos element. It then applies the function/handler to each matching element that caused the event (which will be the single LI
under the mouse).
Upvotes: 8