Created
November 13, 2009 02:32
-
-
Save scottgonzalez/233531 to your computer and use it in GitHub Desktop.
jQuery object normalization
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
function element(value, context) { | |
var ret = $([]); // $(context) ? | |
if (value.jquery) { | |
ret = value; | |
} else if (value == 'parent') { | |
ret = $(context).parent(); | |
} else if (value == 'clone') { | |
ret = $(context).clone().removeAttr('id'); | |
} else if (value == 'window') { | |
ret = $(context).window(); // requires .window() plugin | |
} else if (value.nodeType || typeof value == 'string' || $.isArray(value)) { | |
ret = $(value, context); | |
} else if ($.isFunction(value)) { | |
ret = value(context); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jzaefferer haha, I just comment. I don't tried the code, for me are ok. :(