Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created Aug 13, 2010
Embed
What would you like to do?
/**
* `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