-
-
Save adamturtle/9554a02282011304bfc1 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Takes a jQuery collection and wraps each 'groupSize' items with 'wrapHtml' | |
* Example: $('#Example span').wrapInGroups('<div/>', 4); | |
* Will wrap every 4 span's inside #Example with a div | |
* See for yourself: http://jsfiddle.net/M9ZFh/ | |
* Author: iMoses (imoses.g@gmail.com) | |
*/ | |
(function($) { | |
$.fn.wrapInGroups = function(wrapHtml, groupSize) { | |
var selector = this.selector; | |
groupSize = groupSize || 1; | |
this.filter(':nth-child(' + groupSize + 'n+1)').each(function() { | |
$(this).nextAll(selector + ':lt(' + (groupSize - 1) + ')').andSelf().wrapAll(wrapHtml); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment