Skip to content

Instantly share code, notes, and snippets.

@bruno-c
Created May 24, 2011 16:48
Show Gist options
  • Save bruno-c/989096 to your computer and use it in GitHub Desktop.
Save bruno-c/989096 to your computer and use it in GitHub Desktop.
jQuery plugin that creates a 'subquery' object - basically lets you work with a specific chunk of elements or with detached elements in a way that's less annoying.
jQuery.fn.subquery = function(){
var ctx = $(this);
return function(){
return arguments.length ? ctx.find.apply(ctx, arguments) : ctx;
};
};
// Given something like:
// <article id="article1">
// <h3>foobar</h3>
// </article>
// var $$ = $('#article1').subquery();
// console.log( $$('h3').text() ); --> 'foobar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment