Created
October 25, 2012 15:43
-
-
Save etch-snippets/3953492 to your computer and use it in GitHub Desktop.
[jQuery] Is an element descended from another
This file contains 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($) { | |
$.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