Jquery Click function excluding child elements

on May.12, 2011, under Technology

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

[js]
$(".example").click(function(){
$(this).fadeOut("fast");
}).children().click(function(e) {
return false;
});
[/js]

However it was disturbing some click functions I made for the child
elements, so, I built something a little better:

[js]
$(".example").click(function(data, handler){
if (data.target == this) {
//Do Stuff (only element clicked, not children)
}
});
[/js]

Not very complex.

:,

4 Comments for this entry

Leave a Reply