Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Created July 31, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadamwhite/f1343945ee619b82be98 to your computer and use it in GitHub Desktop.
Save kadamwhite/f1343945ee619b82be98 to your computer and use it in GitHub Desktop.
#angularjs channel question
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