Jquery Click function excluding child elements
I’ve been searching for a way to make a click function work
only on a certain element, excluding the element’s children..
After a short search, I’ve found this function
1
2
3
4
5
$(".example").click(function(){
$(this).fadeOut("fast");
}).children().click(function(e) {
return false;
});
However it was disturbing some click functions I made for the child
elements, so, I built something a little better:
1
2
3
4
5
$(".example").click(function(data, handler){
if (data.target == this) {
//Do Stuff (only element clicked, not children)
}
});
Not very complex.
Posted in Technology