Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Created July 1, 2011 13:58
Show Gist options
  • Save craigmdennis/1058591 to your computer and use it in GitHub Desktop.
Save craigmdennis/1058591 to your computer and use it in GitHub Desktop.
Descendent of - jQuery Plugin
(function($) {
$.fn.descendantOf = function(parentId) {
return this.closest(parentId).length != 0;
}
})(jQuery)
/*
* USAGE
* $('#element').descendantOf('#another-element'); if #element is within #another-element then this will return true
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment