jquery: if (target) is child of ('.wrapper') then (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()
if($(target).parents('.wrapper').length > 0) {
//do something...
}