Is there any elegant way of turning [$(div), $(span), $(li)]
into $(div, span, li)
?
What I need is a jQuery-wrapped set of elements instead of
You can use the add
method to copy the elements in a jQuery object to another. This will copy all elements from each of the jQuery objects in the array source
into the jQuery object items
:
// Create an empty jQuery object
var items = $([]);
// Add the elements from each jQuery object to it
$.each(source, function(){ items = items.add(this); });
(Prior to version 1.3.2 the add
method doesn't support adding a jQuery object, so you would need to use items.add(this.get());
instead.)