Created
December 15, 2010 14:21
-
-
Save rafbm/741985 to your computer and use it in GitHub Desktop.
Returns an array of jQuery objects, grouped by specified number of elements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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