Reputation: 1227
I am trying to hide a div and its children when the div is clicked, but not when any event occurs to any of its children; such as, swipe, tap, or click.
The jQuery that hides the div on click is simple:
$("#tabs").click(function(){
$(this).fadeOut();
});
But I've noticed that when it's children are clicked or swiped, the div fades out.
How can I prevent the div from fading out when those events occur on its children, but allow it to fade onclick
of only itself?
Upvotes: 3
Views: 1576
Reputation: 318342
Check if the element clicked is the same element that was bound:
$("#tabs").click(function(e){
if (e.target == this)
$(this).fadeOut();
});
Upvotes: 9