Created
November 21, 2011 11:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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