var pairs = []; $('div.feature').each(function(i, div) { var i_over_2 = Math.floor(i / 2); if (!pairs[i_over_2]) pairs[i_over_2] = $(); pairs[i_over_2] = pairs[i_over_2].add(div); }); $.each(pairs, function(i, p) { p.doSomethingToAPair(); });
The idea is to create an array of jQuery objects.
edit looks like 1.4 added "$ ()" to get an empty jQuery object.
change again durr Javascript has a float :-)
Hey @ Adam: if we had this jQuery extension (this is of course the toy version):
jQuery.fn.zip = function(s) { var o = $(s); return this.map(function(i, e) { return $(e).add($(o[i])); }); };
then we could build an array of "pairs" as follows:
var pairs = $('div.feature:even').zip('div.feature:odd');
Pointy
source share