I have a function that I want to be able to allow passing in either a regular javascript DOM element object or a jQuery object. If its not yet a jQuery object I will then make i
The easiest way is to simply pass it into the jQuery function either way. If it's already a jQuery object, it will return it unchanged:
function(elem){
elem = $(elem);
...
}
From the jQuery source code, this is what's happening:
if (selector.selector !== undefined) {
this.selector = selector.selector;
this.context = selector.context;
}
return jQuery.makeArray( selector, this );
Where makeArray is merging the new (default) jQuery object with the passed in one.