Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.