Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created December 15, 2010 14:21
Show Gist options
  • Save rafbm/741985 to your computer and use it in GitHub Desktop.
Save rafbm/741985 to your computer and use it in GitHub Desktop.
Returns an array of jQuery objects, grouped by specified number of elements.
/*
* Returns an array of jQuery objects, grouped by specified number of elements.
*
* Say you have 17 <frameset> tags on your page...
*
* $('frameset').inGroupsOf(7); // => [ jQuery[0..6], jQuery[7..13], jQuery[14..16] ]
*
*/
$.fn.inGroupsOf = function( countPerGroup ) {
var groups = [], offset = 0, $group;
while ( ($group = this.slice( offset, (countPerGroup + offset) )).length ) {
groups.push( $group );
offset += countPerGroup;
}
return groups;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment