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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With