4 ms·
Or even simpler: var collected = $('a').map($) However, map as defined on jQuery objects takes a function that takes the index as the first argument, and
by mwilliamson 16y ago
Or even simpler:
var collected = $('a').map($)
However, map as defined on jQuery objects takes a function that takes the index as the first argument, and the element as the second argument:
http://api.jquery.com/map/ http://api.jquery.com/map/
So, what you actually want is:
var collected = $('a').map(function(index, element) {return $(element)})
However, jQuery.map has the element as the first argument, and the index as the second argument:
http://api.jquery.com/jQuery.map/ http://api.jquery.com/jQuery.map/
I would consider this to be the more intuitive way round, although I'd prefer it if both maps were consistent. So, you could write:
var collected = $.map($('a'), $)
which strikes me as the neatest version.