Skip to content

Instantly share code, notes, and snippets.

@ickata
Last active August 29, 2015 14:07
Show Gist options
  • Save ickata/4fa4605caf4fa0eef0e4 to your computer and use it in GitHub Desktop.
Save ickata/4fa4605caf4fa0eef0e4 to your computer and use it in GitHub Desktop.
(MooTools) Additional method in Element.prototype - getParentLimited - traverse DOM tree up to `limit` elements; returns null if `selector` does not match
Element.implement({
getParentLimited : function ( selector, limit ) {
limit = typeOf( limit ) == 'number' ? limit : 10;
var element = this;
do {
element = element.getParent();
} while ( element && ! element.match( selector ) && --limit > 0 );
return limit ? element : null;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment