Simply return your new collection. How you get your new collection
from the current object may well involve map(), but however you do it,
all you need to do is return whatever collection you want to continue
the chain with. It is probably advisable to use pushStack(), so that
your original collection can be retrieved further along the 'chain' if
desired (by using end()).

eg.

$.fn.myMethod = function() {
    return this.pushStack( this.map(function(i,elem) {
        //
        // return newElement
        //
      }) );
};

or

$.fn.myMethod = function() {
    var returnObject = [];
    this.each(function() {
        // var newElement = something based on 'this'
        // returnObject.push(newElement);
      });
    return this.pushStack(returnObject);
};

or variations thereof.

On Dec 12, 3:01 am, McLars <[EMAIL PROTECTED]> wrote:
> I have a plugin that needs to return a different jQuery collection
> than the one it was passed. In other words, each of the elements
> passed in the original collection will create a new element, and I
> want to return the new elements instead of the originals.
>
> So, instead of something like this:
>
> $.fn.myMethod = function() {
>     return this.each(function() {
>     //
>     // Create new element here
>     //
>
> });
>
> which returns the original element collection (preserves chaining),
> I'm looking for an elegant way to return the new elements in a jQuery
> collection.
>
> I think maybe the $.map method might be part of the solution, but I'm
> afraid I just can't understand how. Any help would be appreciated.
>
> Thanks,
>
> Larry

Reply via email to