Skip to content Skip to sidebar Skip to footer

Aggregating A Jquery Object?

I'm authoring a plugin, and the plugin needs to do something like aggregate a set of jQuery objects. How does one do this? For example:

...

&l

Solution 1:

jQuery also accepts an array, so you can build your own node stack and create a jQuery object out of it.

Example:

(function( $ )
{
    $.fn.myfunc = function( settings )
    {
        var stack = [];
        stack.concat(this.find('a').toArray());
        stack.concat($('a.hot-links').toArray());
        return $($.unique(stack));
    };
})(jQuery);

Or simply:

returnthis.find('a'); // as return result of plugin

Also, look at .pushStack(), which lets you add elements to an already existing jQuery object.

Post a Comment for "Aggregating A Jquery Object?"