var target = $(this).attr("href");
if {target is child of ('.wrapper')} then (do something)
simple syntax? can someone show me the correct syntax here?
var target = $(this).attr("href");
if {target is child of ('.wrapper')} then (do something)
simple syntax? can someone show me the correct syntax here?
if($(target).parents('.wrapper').length > 0) {
//do something...
}
.has()
is maybe the mose convenient syntax:
if( $('.wrapper').has($(target)) ) {
// do something
}
Even more 'powerful' (in terms of performance) is $.contains()
. So an ideal algorithm should look like:
var $wrapper = $('.wrapper'),
$target = $(this).attr('href');
if( $.contains($wrapper[0], $target[0]) ) {
// do something
}
Reference: .has(), $.contains()
Can't you bind another event?
$('.wrapper *').click(function() {
// will execute on childrens of .wrapper
});
Small change to Jacob's code, if the child is deeper than one level in.
if($(target).parents('.wrapper').length) {
//do something...
}