Created
July 31, 2015 16:09
-
-
Save kadamwhite/f1343945ee619b82be98 to your computer and use it in GitHub Desktop.
#angularjs channel question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isWithin( className, node ) { | |
// Strip off leading period: classList api doesn't use CSS selectors | |
className = className.replace( /^\./, '' ); | |
// If we're all the way up the tree and haven't found a match, stop | |
if ( ! node.parentNode || node.parentNode.tagName === 'BODY' ) { | |
return false; | |
} | |
// If we've found a match, return true | |
if ( node.parentNode.classList.contains( className ) ) { | |
return true; | |
} | |
// We're not at the top level yet, but this node's parent isn't the | |
// class we want: go up one level and try again | |
return isWithin( className, node.parentNode ); | |
} | |
angular.element(document).bind("click", function(e , r){ | |
console.log( isWithin( '.pilot', e.target ) ) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment