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 an array of jQuery elements. I would like to do this in as few lines of code as possible, and with minimal (if any) looping.
Edit: For those of you confused by this question, this code is copied and pasted from firebug using console.log on an array of elements that have already been selected.
jQuery’s
map()function is perfect for reshaping arrays and/or jQuery collections.So, given an array set like so:
This one line of code is all you need (See it in action at jsFiddle):
Resulting in this console display in Firebug:
Reference, also, jQuery’s
.toArray()function.