Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created November 21, 2011 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/1382389 to your computer and use it in GitHub Desktop.
Save barneycarroll/1382389 to your computer and use it in GitHub Desktop.
Create a quick reference to a $ context, useful for concise and readable $('thing').find() shortcuts
/*
Return $ function limited to current context.
e.g
if:
var $widget = $('widget').scope()
then:
$widget() == $('widget')
$widget('a') == $('widget').find('a')
*/
$.fn.scope = function(){
var $el = this;
return function(x){
return x ? $el.find(x) : $el;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment