Created
April 6, 2014 15:45
-
-
Save bluehazetech/10007813 to your computer and use it in GitHub Desktop.
jQuery: hasParent Selector Function
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
/* | |
* Test whether argument elements are parents of the first matched element | |
* @return boolean | |
* @param objs | |
* a jQuery selector, selection, element, or array of elements | |
*/ | |
$.fn.hasParent = function(objs) { | |
// ensure that objs is a jQuery array | |
objs = $(objs); var found = false; | |
$(this[0]).parents().andSelf().each(function() { | |
if ($.inArray(this, objs) != -1) { | |
found = true; | |
return false; // stops the each... | |
} | |
}); | |
return found; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment