Created
August 13, 2010 10:08
-
-
Save padolsey/522643 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* `and` plugins for jQuery | |
* --- | |
* Pretty intuitive. Enables stuff like: | |
* $('a').andChildren(); | |
* Quicker & easier than: | |
* $('a').children().andSelf() | |
*/ | |
(function(){ | |
var methods = [ | |
'parent', 'parents', 'parentsUntil', | |
'children', 'find', 'siblings', | |
'next', 'nextAll', 'nextUntil', | |
'prev', 'prevAll', 'prevUntil', | |
'closest' | |
]; | |
jQuery.each(methods, function(i, meth){ | |
meth = jQuery.fn[this]; | |
jQuery.fn[ | |
'and' + this.charAt(0).toUpperCase() + this.substring(1) | |
] = jQuery.extend( | |
function() { | |
return this.pushStack(this.add( | |
meth.apply(this,arguments) | |
)); | |
}, | |
meth | |
); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment