Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created August 13, 2010 10:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padolsey/522643 to your computer and use it in GitHub Desktop.
Save padolsey/522643 to your computer and use it in GitHub Desktop.
/**
* `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