I don't understand why, when using stopPropagation()
or stopDefault()
with jQuery, you have to introduce a param to the callback in the event handler function. How does the browser know what to pass in to that function? Also, why doesn't using this
work?
Here's the code that works. I've bolded/asterisked the part that is confusing:
$(document).ready(function() {
$(".see-photos").on("click", function(**event**) {
event.stopPropagation();
$(this).closest(".tour").find(".photos").slideToggle();
});
$(".tour").on("click", function() {
alert("This should not be called");
});
});
To me, it would make more sense this way. Note there is no event
param for the callback in the handler function.
$(document).ready(function() {
$(".see-photos").on("click", function() {
$(this).stopPropagation();
$(this).closest(".tour").find(".photos").slideToggle();
});
$(".tour").on("click", function() {
alert("This should not be called");
});
});